When should I use a form in html

advertisements

With Ajax and dynamic pages seeming to take over the Internet when should one use an HTML form? I can think of a few places(login pages, or really any static page that doesn't change dynamically)

What really has come to mind is things like knockout where you have a model that can control the HTML on the page. You would t really have to do a form submit since you have the model in json and you can just do an Ajax call to send the data to the server.

I always figured forms added extra protection than just doing an ajax request, although I understand that you should never ever trust user input.


Forms are used, basically, for user input. Why use <form> over just GetElementById when passing through AJAX? I was facing a similar question just today, and I concluded the answer was so I could use this piece of code:

$("#YOUR_FORM").submit( function () {
    serialized = $(this).serializeArray(); // <-- this saves time

Other than that, is <form> needed in a modern jQuery-based application? Not as far as I can see, but maybe someone more experienced than me will know why. Also I suppose it adds some organization...

If you're unfamiliar with that function, it will do the work of collecting your form data and putting it into the $_POST array for you, for whatever serverside file you're POSTing to.