To solve the problem of submitting multiple input tags with the same name attribute value in form Processing in php, forminput
Question 1
In the company's development process, I encountered a problem: how to handle the form that submitted multiple input tags with the same name attribute values? The source code is as follows (the source code is in the form ):
<!--{loop $address $index $one}--><div 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></div><!--{/loop}-->
Solution 2
In the source code above, multiple input elements with the same name attribute value are generated in the form through loop. When you click Submit, the php file in the background uses $ _ POST to only obtain the value passed by the input element in a div element. However, the input value of the radio type must be the selected one. Modify the Same name attribute value of some input elements in the source code as an array, and then use the name attribute value of the selected radio type input element in the background php file, determine the entire div element. The modified code is as follows:
<!--{loop $address $index $one}--><div 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></div><!--{/loop}-->
Php file:
$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];
The above section describes how to solve the problem of submitting multiple input tags with the same name attribute values for php form processing. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!