PHP radio button validation help?

  • Thread starter Thread starter titchyc
  • Start date Start date
T

titchyc

Guest
Can anyone help.

i have a form for selecting either 1 or 2, but need to validate it so that if none are selected it shows an error before they ca move to next stage. the code i have is as follows:

echo '<form action=myfile.php name=something method=post>';
foreach( $var1 as $var2 ) {
echo '<input type=hidden name=name value='. $var2[number] .'>';
<input type=radio name=answer value=Yes>*YES;
<input type=radio name=answer value=No>*NO

echo '<br/><br/><input type=submit name=submit value="next">
}
echo '</form>';
 
if($_POST['answer'] == ""){
echo "You go back and give me some info!";
}
else{
echo "Thanks!";
}

or

if(count($_POST) == "0"){
echo "You go back and give me some info!";
}
else{
echo "Thanks!";
}
 
Back
Top