HTML Form Submission Summary

Source: Internet
Author: User
Tags html form

Http://www.cnblogs.com/shizqiang/p/5984414.html

Overview: With the rise of HTML5, the front end more and more diverse, such as the submission of forms, now there are many ways to choose, the following summarizes the common form submission method.

1. The most basic form submission.

<! DOCTYPE html>

The above code is very simple, note that the OnSubmit property in the from form must have a return, otherwise it will be ineffective. The OnSubmit property is optional, if you need JS to do some simple validation of the form, then you can use this way to do, JS if the validation does not pass the return false, then the form is not committed.

<! DOCTYPE html>

Slightly modified above, the form element added the ID, removed the onsubmit, and a type of the submit input button was also removed, instead of adding a normal button outside the from.

This button click will trigger a section of JS, in this JS can do data validation, if the verification through, then through the JS submission form, form form the function of adding ID is for JS to get form elements become convenient.

The above two methods are the most basic way to submit a form, the actual work can be arbitrarily selected.

2.FormData form submission.

Next, we look at the submission of the form through HTML5 's Formdata, which is submitted asynchronously, and the address of the browser is not changed.

<! DOCTYPE html>

This way of committing to the previous two, async is the biggest difference, so one of the benefits of uploading files asynchronously is very cool. Add an INPUT element of type file to the form, it can be uploaded directly, it is very convenient.

3. Use jquery to send the Formdata form.

<! DOCTYPE html>

4. Send the binary file data directly.

<! DOCTYPE html>

Server receives:

<?PHP$FP = fopen (' avatar.png ', ' WB '), $size = Fwrite ($fp, file_get_contents (' Php://input '));p rint ' success ';

Receives the binary data in a stream manner. Complete!!!

HTML Form Submission Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.