Page 1 of 1

Form Validation - Radio Buttons [SOLVED]

Posted: Mon Apr 14, 2008 10:39 am
by eymorais
I've got a llittle problem today.

Trying to validate a form radio button.

My form is on the first PHP file, and my validation is done on a 2nd page, and if an error is detected, it goes back to the first page and the error is posted with the help of a few case arguments.

This is the code I have for my radio button.

Code: Select all

<form .....>
<input type="radio" name="comment_pckg" value="Select"> Select<br>
<input type="radio" name="comment_pckg" value="Plus"> Plus<br>
<input type="radio" name="comment_pckg" value="Plus"> Total<br>
</form>
They are initially uncheck and at least one needs to be selected for the form to be valid.

If tried both following php codes with no luck....

Code: Select all

 
if ($_POST["comment_pckg"].unchecked)
{
    //redirect back to form
    header("Location: ../form.php?error=package_missing");
    exit();
} 
 
& I've tried this.

Code: Select all

if (empty($_POST["comment_pckg"]))
{
    //redirect back to form
    header("Location: ../form.php?error=package_missing"); 
    exit();
}
Any ideas???

Re: Form Validation - Radio Buttons

Posted: Mon Apr 14, 2008 10:46 am
by andym01480
Try

Code: Select all

if (!isset($_POST['comment_pckg']))
{
    //redirect back to form
    header("Location: ../form.php?error=package_missing"); 
    exit();
}
Note single quotes for $_POST too!

Re: Form Validation - Radio Buttons [SOLVED]

Posted: Mon Apr 14, 2008 12:26 pm
by anto91
@up: there is no differeance apart form the fact that most good developer habits are to use single quotes.

@thread: Are you sure that the form is sending a POST request and not a GET?