Resolves an input label issue in which PHP handles form form submissions with multiple Name property values

Source: Internet
Author: User
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];

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.