This article mainly describes the resolution of the PHP processing form form to submit multiple name attribute values the same input label problem, has a certain reference value, now share to everyone, the need for friends can refer to
A problem
During the company's development, a problem was encountered: How do I handle a form form that submits multiple input tags with the same value as the name attribute? The source code is as follows (the source code is in the form form):
<!--{loop $address $index $one}--><p class= "Address_item" > <p> <label> < Input type= "hidden" name= "Express_price" value= "{$one [' Express_price ']}"/> <input type= "hidden" name= " State_fare "value=" {$one [' State_fare ']} "/> <input type=" hidden "name=" id "value=" {$one [' id ']} "/> <input type= "Radio" <!--{if $one [' Default ']== ' Y '}-->checked<!--{/if}-->name= ' address ' value= ' {$one [ ' ID ']} "/><span name=" mobile ">{$one [' Mobile ']}</span> </label> </p></p> <!--{/loop}-->
Two-way solution
In the above source code, through the loop loop, in the form form to generate multiple name attribute values of the INPUT element, when click Submit, the background php file using $_post can only get to a P element of the INPUT element passed the value, but the radio type I The value passed by the Nput element must be the one selected. Accordingly, modify the above source in some input elements of the same name attribute value of the array, and then in the background php file through the selected radio type INPUT element name attribute value, determine the entire P element passed over. The modified code is as follows:
<!--{loop $address $index $one}--><p class= "Address_item" > <p> <label> < Input type= "hidden" name= "express_price[]" value= "{$one [' Express_price ']}"/> <input type= "hidden" name= " State_fare[] "value=" {$one [' state_fare '} "/> <input type=" hidden "name=" id[] "value=" {$one [' id ']} "/> <input type= "Radio" <!--{if $one [' Default ']== ' Y '}-->checked<!--{/if}-->name= ' address ' value= ' { $one [' ID ']} "/> <span name=" mobile ">{$one [' Mobile ']}</span> </label> </p> </p><!--{/loop}-->
PHP Files:
$key = 0; $address _id = Intval ($_post["Address"]), foreach ($_post[' id ') as $k = + $v) { if ($v = = $address _id) $ key = $k;} $_post[' Express_money '] = $_post[' Exporess_price ' [$key];