Jump to content

Testing whether a radio button was checked


burntheblobs

Recommended Posts

				<tr>
			<td>
				<input type='radio' name='experienceRating' value='0'>
			</td><td>
				<input type='radio' name='experienceRating' value='1'>
			</td><td>
				<input type='radio' name='experienceRating' value='2'>
			</td><td>
				<input type='radio' name='experienceRating' value='3'>
			</td><td>
				<input type='radio' name='experienceRating' value='4'>
			</td><td>
				<input type='radio' name='experienceRating' value='5'>
			</td><td>
				<input type='radio' name='experienceRating' value='6'>
			</td><td>
				<input type='radio' name='experienceRating' value='7'>
			</td><td>
				<input type='radio' name='experienceRating' value='8'>
			</td><td>
				<input type='radio' name='experienceRating' value='9'>
			</td><td>
				<input type='radio' name='experienceRating' value='10'>
			</td></tr>


	if ($field == "experienceRating")
		{
			if ($value == "")
		{
			echo "<font color='red'>You have not filled in a ";
			convertLabel($field);
			echo "!<br></font>";
			$badform = "yes";
		}

Link to comment
Share on other sites

Thank you for the reply. I modified the code in a way that it SHOULD work, but it still doesn't work for some reason. Here is my code.

 

		if ($field == "Age" or $field == "firstRating"  
			or $field == "secondRating"  or $field == "thirdRating")
		{
			if (empty($_POST[$field]))
		{
			echo "<font color='red'>You have not filled in a ";
			convertLabel($field);
			echo "!<br></font>";
			$badform = "yes";
		}

Link to comment
Share on other sites

All of this is inside a foreach loop. $field is the field name. $value is what is entered into the field.

foreach ($_POST as $field => $value)

where is $field being generated?  as far as i can see, $field has no value.

 

and as far as your foreach loop, $field will be set as the key in the array.

Link to comment
Share on other sites

I have a form in another spot in the program that generates the $field. I was under the impression that $_POST was an array that you could assign a key and a value to. It seems to be working for all my other processes. Sorry for not including code earlier, I realize this it's kind of hard to help me when I'm being stingy with code.  :) Anyway, I was thinking that "experienceRating" would be the $field and $value would be whatever the value was.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.