PHP+JS processing of large input input box and form submission acquisition problem

Source: Internet
Author: User

Recently received a more exotic demand, the other side requested in the enterprise station to add a similar word form, and for users to fill out and submit online.

After a closer look, the form has a field as high as 100, and this magnitude is quite scary. If each input manually to fill in the ID and name, what a terrible physical life ah.

Repeatedly think about it, in order to avoid the bitter forced to fill in the ID and name of the input, decided to use JS with PHP to solve this form a series of submissions.

Form components

Form first according to customer requirements, the required form and options will be completed according to the prototype of the Word document layout to meet the user experience, the following figure:

(The image above is just a small part of the interception form as an example, in fact, the form is incredibly large)

When the HTML layout of the form is complete, we need to start with the input setting ID and name of these forms for the form submission.

The foreword has already said that the input is very many, therefore we use the JS way to add the ID and name automatically for the input. The code is as follows (jquery method):

The code is as follows Copy Code
$ (document). Ready (function () {
var inputnum = 0;
$ (' input '). each (function () {
$ (this). attr ({name: ' val ' +inputnum,id: ' val ' +inputnum});
inputnum++
})})

After JS processing, all the input of the page will automatically add 1 to the ID and name. At this point, the form can be used basically. (Frome we don't explain, programmers understand.) )

Form Get part

OK, the above can be normal to submit the form to the PHP program for processing. Of course, the above method also applies to any kind of Web program, such as. net,jsp,asp and so on.

Next we need to disassemble the submitted string to get the values in the form. This article does not explain how to get the pass value of a form.

Because the value of table conveys is also n, so we can not write an array variable to get these values, so there are some ways to deal with.

OK, here we are. First of all, we think of the previous JS program logic, how to let these arrays each self-add to achieve the output of the array.

The program code is as follows:

The code is as follows Copy Code

<?php
$num = 0; Initializing count variables
$_request[' Val '. $num]; $num + +; Insert where you want to get the value, and use this code repeatedly for each place you need to get the value.
?>

This group of code is mainly used in the form input and request order in the same situation, if not the corresponding order, there will be confusion. So use the time need to be careful!

When submitting a database, it is convenient to consider using a foreach method to process the acquired parameters into an array and then insert the database.

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.