Recently in a inquiry message management system when a problem, the message of the front desk in the form of a lot of the same name value of the input box, these boxes are filled by users of different values, and now to migrate to the PHP platform, and requirements can not change the front of any form (because the site used to this form is too much, so you must consider the compatibility of transfer, even the form's submission address can not change, must be submitted to an ASP page). Form submits address problem, can use pseudo static or other method to solve directly. Since the previous system was made by ASP, ASP in processing the same name value of the form, is the direct use of commas to the value of the foreground submitted, and PHP is not the same, it receives the same name of the input, is the last one to cover up the previous value. So how do you get the value of all of the input values that are in the same name without rewriting the foreground? There were two ideas in mind, the first is to let this input of the name of the array to the background, and then to deal with, but was quickly rejected, because this also has to change the foreground code, so that
<input type= "text" name= "a"/> changed to <input type= "text" name= "a[" "/>". The second idea is that the PHP configuration, there is no similar setting to allow PHP like ASP to process the same name value of the form, search for a half-day data, also did not find.
Finally found that only to return to the second, a little change to the front desk, the name into an array, fortunately, so the use of the site is not much. Then is the background to deal with the data problem, the front of the name of a part of the change, this time there will be a situation, PHP does not know the form submitted by the string or array, then how to do it, my approach is to write a function:
function Input_treat ($input) {
if (GetType ($input) = = "string") {return
htmlentities (Trim ($input), ent_quotes );
} else if (GetType ($input) = = "Array") {
$nd = "";
foreach ($input as $v) {
$nd. =htmlentities (Trim ($v), ent_quotes). " ";
}
return $nd;
} else{return
false;
}
Using the Input_treat () function to handle the value of Get or post, if it is a string, then handle the string back, if it is an array, iterate through the input, connect each element of the array with a space, and return the entire string.
In this way, the whole requirement is realized, the disadvantage is that a site that uses the same name form must change the data, if you have a better way, please contact me and message.