Click to See Complete Forum and Search --> : [RESOLVED] radio buttons not submitting if not clicked


steamPunk
09-25-2009, 08:52 AM
Hi

I've got a problem i've never had before :

I have a form with various fields including some radio buttons :
<input name="user_civ" type="radio" value="M." class="radio" /> M.
<input name="user_civ" type="radio" value="Mme" class="radio" /> Mme
<input name="user_civ" type="radio" value="Mlle." class="radio" /> Mlle.
<input name="user_civ" type="radio" value="n/c" class="radio" /> n/c

and I'm testing the submitted values using php

when one of the radio buttons is selected the value of $_POST['user_civ'] is submitted normally

but if no buttons are selected the $_POST['user_civ'] isn't sent with the other form variables - is this normal behaviour ?

thanks

ryanbutler
09-25-2009, 09:08 AM
Yes, b/c radio buttons are treated as boolean in programming languages. You could always do something like:


<?php

if($_POST['user_civ']!=""){
//the value
}else{
//echo "No value";
}

steamPunk
09-25-2009, 09:23 AM
ok, that makes sense - my server-side form validation normally loops through the post vars and checks which required fields are empty - but this wasn't checking because it wasn't even in the $_POST array !

thanks