bsowards
asked on
Radio Input throwing Undefined Index
Hi,
I have a form that submits values from the following radio button:
<td height="185" align="left" valign="top">
<p><font face="Tahoma" size="2">How many people (on average) will be watching this presentation? <br>
<input type="radio" name="Watching" value="Less than 5">
Less than 5 <br>
<input type="radio" name="Watching" value="6 to 15">
6 to 15<br>
</font><font face="Tahoma" size="2">
<input type="radio" name="Watching" value="16 to 30">
16 to 30 <br>
<input type="radio" name="Watching" value="31 to 100">
31 to 100 <br>
<input type="radio" name="Watching" value="101 to 500">
101 to 500 <br>
<input type="radio" name="Watching" value="More than 500">
More than 500</font></p></td>
I then submit the code to another page where I attempt to verify it:
function cleantext($text)
{
if( isset( $text )){
return $text;
} else {
$r = "";
return $r;
}
}
//Submission conversion
$Watching = cleantext($_POST["Watching "]);
But i get the error:
Notice: Undefined index: Watching in C:\Sites\Single27\bsowards \webroot\p resteam\Se rvices\Pac kaged\3 Templates\formsubmit.php on line 49
I'm using PHP 5 on Windows Server 2003, can anyone tell me how to check if a Radio submitted value is valid? is it because it is an array? Sample code would be much appreciated thanks!
I have a form that submits values from the following radio button:
<td height="185" align="left" valign="top">
<p><font face="Tahoma" size="2">How many people (on average) will be watching this presentation? <br>
<input type="radio" name="Watching" value="Less than 5">
Less than 5 <br>
<input type="radio" name="Watching" value="6 to 15">
6 to 15<br>
</font><font face="Tahoma" size="2">
<input type="radio" name="Watching" value="16 to 30">
16 to 30 <br>
<input type="radio" name="Watching" value="31 to 100">
31 to 100 <br>
<input type="radio" name="Watching" value="101 to 500">
101 to 500 <br>
<input type="radio" name="Watching" value="More than 500">
More than 500</font></p></td>
I then submit the code to another page where I attempt to verify it:
function cleantext($text)
{
if( isset( $text )){
return $text;
} else {
$r = "";
return $r;
}
}
//Submission conversion
$Watching = cleantext($_POST["Watching
But i get the error:
Notice: Undefined index: Watching in C:\Sites\Single27\bsowards
I'm using PHP 5 on Windows Server 2003, can anyone tell me how to check if a Radio submitted value is valid? is it because it is an array? Sample code would be much appreciated thanks!
ASKER
your debug did not provide any information or did not work. I'm still getting the error with no additional information.
ASKER
whoops! put at end of code so didn't get to it.
It's showing that the value "Watching" isn't even included in the index, which is what I assumed from the error. So how come my detection script isn't handling that?
It's showing that the value "Watching" isn't even included in the index, which is what I assumed from the error. So how come my detection script isn't handling that?
Are the radio buttons between your <form> and </form> tags?
-r-
-r-
Change $_POST to $_GET.
This should match the form's action (POST or GET).
Can you show the complete form you are using?
This should match the form's action (POST or GET).
Can you show the complete form you are using?
ASKER
I don't want to use $_GET, I prefer $_POST.
The form works fine when one of the radio buttons are selected, but doesn't if one isn't. Most sites recommend setting one radio button to the default by putting "checked" on one of the options.
I'd prefer to know how to check if a variable is IN the index, that way I don't have to worry about it. Thanks.
The form works fine when one of the radio buttons are selected, but doesn't if one isn't. Most sites recommend setting one radio button to the default by putting "checked" on one of the options.
I'd prefer to know how to check if a variable is IN the index, that way I don't have to worry about it. Thanks.
if(isset($_POST['Watching' ]))
-r-
-r-
ASKER
Yes well, my function is set to do that, but it doesn't work.
function cleantext($text)
{
if( isset( $text )){
return $text;
} else {
$r = "";
return $r;
}
}
//Submission conversion
$Watching = cleantext($_POST["Watching "]);
function cleantext($text)
{
if( isset( $text )){
return $text;
} else {
$r = "";
return $r;
}
}
//Submission conversion
$Watching = cleantext($_POST["Watching
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
echo '<pre>'.var_export($_POST,
-r-