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):
$ (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:
<?php
$num = 0;//Initialize the count variable
$_request[' Val '. $num]; $num + +///insert to the place where you want to get the value, repeat the code wherever 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.