Forms radio button not displaying

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
heumannt
Forum Newbie
Posts: 2
Joined: Mon Jul 04, 2005 1:40 am

Forms radio button not displaying

Post by heumannt »

I have a forms site that has several fields and 2 radio buttons for gender (male/female).

In the PHP code I have a check to make sure all fields are filled in or selected. This part works. I have tested it with filling in all fields but one (for every field) and it recognizes when one isn't selected.

The problem is when I try to display the $_POST so the user can see what isn't filled in.

This is the PHP code.
echo "<pre>"
print_r($_POST);" command to display the
echo "</pre>"

Here are 2 examples of what comes out. They're self explanitory.
Array
(
[firstName] => ghj
[lastName] => gf
[church] => hgs
[youthLeader] => hds
)
Array
(
[firstName] => ghj
[lastName] =>
[gender] => male
[church] => hgs
[youthLeader] => hds
)

As you can see, the first one will not show that 'gender' is blank but it will show that the string variables are blank.

Any ideas why this would be?
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

FYI, fields will always be submitted even if it's blank. You have to do more validation than you did. For example...

Code: Select all

// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.

Code: Select all

<input type=radio value='male' [color=red]checked[/color]>
<input type=radio value='female'>
God bless. :wink:)&&$_POST['lastname']!='')
$lastname = $_POST['lastname'];
else
$lastname = '';
// if not tell the user
if($lastname=='')
echo &quote;Lastname field not filled in.&quote;;

Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.

Code: Select all

<input type=radio value='male' [color=red]checked[/color]>
<input type=radio value='female'>
God bless. :wink:ed[/color]>
<input type=radio value='female'>

God bless. :wink:more validation than you did. For example...

Code: Select all

// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.

Code: Select all

<input type=radio value='male' [color=red]checked[/color]>
<input type=radio value='female'>
God bless. :wink: check if variable set or filled in
if(isset($_POST['lastname'])&&amp;$_POSTї'lastname']!='')
$lastname = $_POSTї'lastname'];
else
$lastname = '';
// if not tell the user
if($lastname=='')
echo &quote;Lastname field not filled in.&quote;;

Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.

Code: Select all

&lt;input type=radio value=e to do more validation than you did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted iflways be submitted even if it's blank. You have to do more validation than you did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.
[code]
<input type=radio value='male' [color=red]checked[/color]>
<input type=radio value='female'>
[/code]
God bless. :wink:do more validation than you did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option if it's blank. You have to do more validation than you did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.
[code]
&lt;input type=radio value='male' &#1111;color=red]checked&#1111;/color]&gt;
&lt;input type=radio value='female'&gt;
[/code]
God bless. :wink:lways be submitted even if it's blank. You have to do more validation than you did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.
[code]
&lt;input type=radio value='male' &#1111;color=red]checked&#1111;/color]&gt;
&lt;input type=radio value='female'&gt;
[/code]
God blese']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are f it's blank. You have to do more validation than you did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default oyou did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.
[code]
&lt;input type=radio value='male' &#1111;color=red]checked&#1111;/color]&gt;
&lt;input type=radio variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. Avalidation than you did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of thlways be submitted even if it's blank. You have to do more validation than you did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.
[code]
&lt;input type=radio value='male' &#1111;color=red]checked&#1111;/color&did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of lways be submitted even if it's blank. You have to do more validation than you did. For example...
[php]
// check if variable set or filled in
if(isset($_POST['lastname'])&&$_POST['lastname']!='')
  $lastname = $_POST['lastname'];
else
  $lastname = '';
// if not tell the user
if($lastname=='')
  echo "Lastname field not filled in.";
[/php]
Now radioboxes are different, for it will not be submitted if the user didn't select any of them. And it is wise to choose one of them to be the default option.
[code]
&lt;input type=radio value='male' &#1111;color=red]checked&#1111;/color]&gt;
&lt;input type=radio value='female'&gt;
God bless. :wink:
heumannt
Forum Newbie
Posts: 2
Joined: Mon Jul 04, 2005 1:40 am

Post by heumannt »

Awesome. Thanks a bunch. I didn't really want to have one of those defaulted but maybe I will. Or I guess I can write a script to test for that as well. Thank.
Post Reply