PHP easy way to handle a large number of form fields, PHP form fields
On the form batch submission strategy in program development
A lot of times a form is too many fields, how to efficiently get form fields, but also for how to refresh the efficiency and unity of development?
For example a system has 26 fields, then I use the name of the form with 26 A to Z letters,
You are the choice,,......,Traditional form of doing it?
But if you do bulk data insertion in this case, it won't be that simple.
Because the insert or edit operation would be such a statement: Especially in this case, the egg-like SQL string is more painful.
Copy the Code code as follows:
$sql = "INSERT kele_table (A, b,......, z) value (a= ' $a ', b= ' $b ',......, z= ' $z ')";//This is long written Optimus is marked with ellipses
$sql = "UPDATE SET kele_table (a= ' $a ', b= ' $b ',......, z= ' $z ') where id= $id";
This kind of writing is very frustrating, the string is too long
It is better to use one of the following methods:
Point 1: Use the array pattern for the entire submitted form field.
Copy the Code code as follows:
,......,
Point 2:
PHP daemon receives $setting array via post
Point 3:
Insert Form Field Display
Copy the Code code as follows:
$fields =array (' A ', ' B ',......, ' z ');//This is deliberately set up a validation dictionary to verify the existence of the submitted field
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
Copy the Code code 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";
http://www.bkjia.com/PHPjc/954656.html www.bkjia.com true http://www.bkjia.com/PHPjc/954656.html techarticle php easy way to handle a large number of form fields, php form field in the program development of the form of batch submission strategy many times a form too many fields, how to efficiently get the form ...