Form Validation - Radio Buttons [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
eymorais
Forum Newbie
Posts: 14
Joined: Fri Apr 11, 2008 8:38 am
Location: Moncton NB Canada

Form Validation - Radio Buttons [SOLVED]

Post 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???
Last edited by eymorais on Mon Apr 14, 2008 11:48 am, edited 1 time in total.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Form Validation - Radio Buttons

Post 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!
anto91
Forum Commoner
Posts: 58
Joined: Mon Mar 10, 2008 10:59 am
Location: Sweden

Re: Form Validation - Radio Buttons [SOLVED]

Post 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?
Post Reply