PHP is a convenient way to process a large number of form fields, such as php form fields. PHP is a convenient way to process a large number of form fields. php form fields have too many fields in the form batch submission policy in program development, how to efficiently obtain the form PHP convenient way to process a large number of form fields, php form fields
About the form batch submission policy in program development
Most of the time, how can I efficiently retrieve too many fields in a form and improve the efficiency and uniformity of development?
For example, if a system has 26 fields, I use the form name to use 26 letters a to z,
You choose,,......,Is it done in the traditional form?
However, in this case, batch data insertion will not be so concise,
This is because the insert or edit operation is like this: especially the SQL string that is so painful is even worse.
The code is as follows:
$ SQL = "INSERT kele_table (a, B ,......, Z) value (a = '$ A', B =' $ B ',......, Z = '$ Z') "; // enter the ellipsis for a long iron ox.
$ SQL = "update set kele_table (a = '$ A', B =' $ B ',......, Z = '$ Z') where id = $ id ";
The string is too long.
It is better to use the following method:
Key aspect 1: Use the array mode for the entire submitted form field.
The code is as follows:
,......,
Key aspect 2:
PHP background program receives $ setting array through POST
Key aspect 3:
Insert form field display
The code is as follows:
$ Fields = array ('A', 'B ',......, 'Z'); // This is a specially set validation dictionary to verify whether the submitted field exists.
Foreach ($ setting as $ k => $ v ){
If (in_array ($ k, $ fields) {$ sqlk. = ','. $ k; $ sqlv. = ", '$ V '";}
}
$ Sqlk = substr ($ sqlk, 1 );
$ Sqlv = substr ($ sqlv, 1 );
$ SQL = "INSERT INTO kele_table ($ sqlk) VALUES ($ sqlv )";
Update form field display
The code is as follows:
$ SQL = '';
Foreach ($ setting as $ k => $ v ){
If (in_array ($ k, $ fields) $ SQL. = ", $ k = '$ V '";
}
$ SQL = substr ($ SQL, 1 );
$ SQL = "UPDATE kele_table SET $ SQL WHERE id = $ id ";
Tips about the form batch submission policy in program development. many times there are too many fields in a form. how can I efficiently obtain the form...