Radio Button Post Data Of Multiple Input Fields December 05, 2023 Post a Comment I have a form in my PHP page which is created by a loop through an array. echo 'Solution 1: Radio buttons should all use the same name. Only the selected radio button value is submitted:<input type="radio" name="Radiosize" value="'.$arr_get_product_details[$d]['size'].'"> Copythen:$size = $_POST['Radiosize']; CopyThere is no need to look at it as an array - it isn't submitted as one. Radio Buttons are not like checkboxes in form processing.Solution 2: change <inputclass="qty"type="text" size="3" name="amount" value="1"> Copyto <inputclass="qty"type="text" size="3" name="amount[]" value="1"> Copyand then you will have 2 arrays that will have same size.<?php$size = $_POST['size'][0]; $amount = $_POST['amount'][$size]; ?>CopySolution 3: Form code: <input type="radio" name="size" value="'.$arr_get_product_details[$d]['size'].'"> <input class="qty"type="text" size="3" name="amount['.$arr_get_product_details[$d]['size'].']" value="1"> CopyAnd then you will have value of size. And array of amounts with size keys.$size = $_POST['size']; $amount = $_POST['amount'][$size]; CopySolution 4: I solved the issue by doing the following.Baca JugaHow To Design A Radio Button, Which Looks The Sam In Firefox, Chrome And Ie11Html: How To Indicate Questions With Radioboxes As Answers In Proper Way?Selecting Multiple Radio Buttons With AlertThe guys above here all got me on the right track and couldn't have done it without them!Changed<inputtype="radio" name="size[]" value="'.$arr_get_product_details[$d]['size'].'"> <inputclass="qty"type="text" size="3" name="amount" value="1"> CopyTo<input type="radio" name="size['.$d.']" value="'.$arr_get_product_details[$d]['size'].'"> <input class="qty"type="text" size="3" name="amount['.$d.']" value="1"> CopyAlso changed if (isset($_POST['add_to_chart'])) { $product_id = $_POST['product_id']; $size = $_POST['size'][0]; $qty = $_POST['amount']; } CopyTo thisif (isset($_POST['add_to_chart'])) { // Array ID key$key = key($_POST['size']); $product_id = $_POST['product_id']; $size = $_POST['size'][$key]; $qty = $_POST['amount'][$key]; } CopyWorks like a charm! Thank you all for your very helpful comments! Share You may like these postsHtml Form Library For Php 5Submitting 2 Forms At The Same Time Using JavascriptForm Button Refreshes On Click - One Page WebsiteHow To Use Onsubmit() To Show A Confirmation If There Are Multiple Submit Buttons On The Same Form? Post a Comment for "Radio Button Post Data Of Multiple Input Fields"
Post a Comment for "Radio Button Post Data Of Multiple Input Fields"