Jump to content

Recommended Posts

I have a set of 10 radio buttons, all with the same name, and I am trying to write something that checks to see if any button has been checked. The simple $value == "" doesn't seem to be working. I also would like to try to avoid checking to see if there isn't a match for every possible value.

				<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";
		}

presuming ur using:  <form action="myphp.php" method="POST" />

 

 

$experienceRating = $_POST['experienceRating'];

 

if($empty($experienceRating)) { echo " empty "; } else { echo " not empty "; }

 

some this like that ?

 

 

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";
		}

wait sorry that's wrong.  Okay what I meant to say is, your inner condition will only execute if your outer one is true, and your outer one will only evaluate true if $field == one of those other things, like $_POST['Age'], not $_POST['experienceRating']. 

 

Where are you assigning something to $field?

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.

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.

  • 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.