1

i was making a website with PHP,jQuery,AJAX,mySQL which has lot of interaction with user. Now what i was asking that using forms are really necessary ?

what i have done for most of my user inputs are kinda like this --> simple e.g

<div class="contact-form">
   <input type="text" class="textInputs" id="name" placeholder="Enter your name..." />
   <button class="submitButton" id="contactSend">Subscribe</button>
</div>

A SIMPLE comment system

<div class="comment-box" d-id="1">
   <input type="text" class="textInputs" id="comment" placeholder="Enter comment..." />
   <button class="submitButton" id="comment">Comment</button>
</div>

<div class="comment-box" d-id="2">
   <input type="text" class="textInputs" id="comment" placeholder="Enter comment..." />
   <button class="submitButton" id="comment">Comment</button>
</div>

JQUERY kinda this->

$('#comment').click(function(){
    var id = $(this).closest('.comment-box').attr('data-id');
//ajax stuff
}):

Therefore what i wanna ask is whether this kinda structure is good or gonna cause some serious problem ? Are using <form>'s compulsory ?

HackerManiac
  • 243
  • 1
  • 4
  • 20
  • 1
    well its still good if your comment box can function properly even if javascript is turned off. just to make sure. – user1978142 May 17 '14 at 11:48
  • how can i t work if js is turned off coz its all dependent on js ! @kevinabelita – HackerManiac May 17 '14 at 11:54
  • im not sayin its bad, just making sure, if the comment box is heavily reliant to js then just add a ` – user1978142 May 17 '14 at 12:02
  • and whats a `noscript` now? – HackerManiac May 17 '14 at 12:03
  • for supplemental information you can check out this [topic](http://webmasters.stackexchange.com/questions/1787/webpage-post-submits-vs-ajax). regarding [noscript](https://developer.mozilla.org/en/docs/Web/HTML/Element/noscript) – user1978142 May 17 '14 at 12:08
  • [this](http://stackoverflow.com/questions/2704753/is-form-tag-necessary-in-ajax-web-application) and [this](http://stackoverflow.com/questions/6309214/why-use-a-form-tag-when-youre-submitting-via-ajax) discussions may also give some perspective. – user1978142 May 17 '14 at 12:13

2 Answers2

-1

If you are submitting form by clicking submit button and posting variable to other pages or the same page then tag is necessary

If you are using form tag to find input values to post using ajax is necessary

If you are using ajax and pulling input values using dom id to post via ajax form is not required, in this case you may also need to do javascript validation using dom ids

Ideally using tag is better and follows standard HTML structure.

sathishn
  • 150
  • 4
-1

It depends upon your requirement and how you going to use the form in your project.

If you have min. no of fields ( 2-3 fields ) in your form. You can directly manipulate the form fields using id or name with JQuery or JavaScript. Otherwise you should have form tag to manipulate the data with more fields in the form.

I would recommend to have form tag in your page to maintain the standard format and use form tag and Ajax submission with Jquery.

Note: Anyway if you are going to get form data using Jquery, better to use the following syntax to get the from values:

// To check the radio button
var isAnsChecked = $("input:radio[name=<FIELDNAME>]").is(":checked");
var radio-value = $("input:radio[name=<FIELDNAME>]:checked").val();

// get Text box values
var text-value = $("input:text[name=<FIELDNAME>]").val();