php form multiple radio buttons

xhallix picture xhallix · Jul 19, 2013 · Viewed 8.5k times · Source

I'm trying to find a generic way to call out which radio button has selected. Problem is, while using $_GET in my foreach loop, also submit button is echo in the loop.

Can anyone tell me how to avoid this, so that I just show up the radio buttons? I do not know a way, because foreach just accepts arrays as far as I know

here is my code

<form action="" method="get">
<input type="radio" name="one" value="One1" />One1<br/>
<input type="radio" name="one" value="One2" />One2 <br/>
<input type="radio" name="one" value="One3" />One3<br/>
<input type="submit" name="submit"/> <br/>
</form>



if(isset($_GET['submit'])){
    foreach( $_GET as $key=>$val){
        echo "$val <br/>";
    }
}

Answer

liyakat picture liyakat · Jul 19, 2013

just try to add if condition in your loop will not show submit button in your form.

if(isset($_GET['submit'])){

    foreach( $_GET as $key=>$val){
      if($key != 'submit')
        echo "$val <br/>";
    }
}

hope it will help you