0

Hi i have a lot of input in my form some of them are radio button and others are text and textbox. I am getting all of these values with

foreach ($_POST as $name => $val)
{
 //for example if post type==radio
 //there is some insertion codes to db in here $name,$val...

}

but i want use that insertion if post value is radio button. How can i do it?

my form looks like

<form method="post" action="<?=$_SERVER['REQUEST_URI']?>">
.
.
.
//a lot of table,tr,td,input,etc. in this part
.
.
.

<td style="border-style:solid; border-width:2px 1px 1px 2px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="1" /></td>
<td style="border-style:solid; border-width:2px 1px 1px 1px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="2" /></td>
<td style="border-style:solid; border-width:2px 1px 1px 1px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="3" /></td>
<td style="border-style:solid; border-width:2px 2px 1px 1px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="4" /></td> 

<td style="border-style:solid; border-width:1px 1px 2px 2px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="1" <?php echo ($plastikKaplama4=='1')?'checked':'' ?>/></td>
<td style="border-style:solid; border-width:1px 1px 2px 1px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="2" <?php echo ($plastikKaplama4=='2')?'checked':'' ?>/></td>
<td style="border-style:solid; border-width:1px 1px 2px 1px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="3" <?php echo ($plastikKaplama4=='3')?'checked':'' ?>/></td>
<td style="border-style:solid; border-width:1px 2px 2px 1px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="4" <?php echo ($plastikKaplama4=='4')?'checked':'' ?>/></td>


<input id='elm2' type="submit" name="save2" value="Submit" />

</form>

to summerize im trying to get all of name and its value of selected radio button with foreach but i dont want to get other intputs such as text and textarea.

Furkan
  • 141
  • 1
  • 13
  • you have a few syntax errors here. Consult these following links http://php.net/manual/en/mysqli.error.php and http://php.net/manual/en/function.error-reporting.php and apply that to your code. – Funk Forty Niner Nov 25 '15 at 16:06
  • The $_POST array does not contain any information on what input type the value came from. You would need to filter based on the name. Or name your select input types something unique like name="select_foo" – Tony DeStefano Nov 25 '15 at 16:08
  • even though you edited, it still contains syntax errors. Use the links I gave you to troubleshoot/debug your code. We also have no idea what your $_POSTs look like. – Funk Forty Niner Nov 25 '15 at 16:08
  • Im trying to apply this in my code. http://stackoverflow.com/questions/7163815/get-name-of-a-post-variable – Furkan Nov 25 '15 at 16:10
  • ok, so where's the form you're using for this? – Funk Forty Niner Nov 25 '15 at 16:11
  • it is form that is 2400 line of input im gonna try to edit my question with part of it – Furkan Nov 25 '15 at 16:13
  • Btw, if you're using radio buttons with the same group name, it won't work. Radio buttons give single choices, as opposed to checkboxes. Do post your HTML form. If you don't have one, then I'm sorry to say, but I won't write that code for you. Edit: then provide us with a minimal example. – Funk Forty Niner Nov 25 '15 at 16:14
  • A form with 2400 inputs? How long does it take the user to fill in this form? – Barmar Nov 25 '15 at 16:18
  • actually radio buttons are grouped 4 by 4 so its not that long to fill them all =) and not all of 2400 are input just few of them. – Furkan Nov 25 '15 at 16:25

1 Answers1

0

You should POST hidden inputs for each input using Javascript

<input type="hidden" name="radio" value="input1,input2" />

then using php

$radios = explode(',',$_POST['radio']);
foreach($radios as $value) {
    $radio_value = $_POST[$value];
    // Do you want
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
Fahed Alkaabi
  • 269
  • 2
  • 10