To solve the problem of submitting multiple input tags with the same name attribute value in form Processing in php, forminput

Source: Internet
Author: User
Tags php form php form processing

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.