Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Radio box selection hell :(

    Help
    i have no idea whats going on with this stoooopid thing! i am soo frustrated!
    i have gender radio buttons which look like this

    <label for="gender">Gender:</label>
    <input type="radio" name="gender" value="male" <?=($gender == 'male' ? 'checked' : ''); ?> >male
    <input type="radio" name="gender" value="female" <?=($gender == 'female' ? 'checked' : ''); ?> >female
    <font size="2" color="red"><?php print "$gendermessage" ?></font><p>

    i then have a little validation code above the html which goes like this

    if (empty($_POST['gender']) || ($_POST['gender'] != "male" && $_POST['gender'] != "female"))
    {
    $gendermessage = "Please enter a gender ";
    $errors ++;

    the problem is when i click female and print $gender after submit it prints female even if i pressed male.
    when i click submit and the page is caught by another field the radio button does not stay empty or at the box which was previously chosen it snaps to female!

    consequently i cannot distinguish between male and female which means none of my application works
    i'm totally baffled- i know i've been asking alot but does anyone know why this is happening?
    in much desperation
    VERYnoobyphpchick

  • #2
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    PHP Code:
    if ($_POST['gender'] != "male" && $_POST['gender'] != "female"))
    {
    $gendermessage "Please enter a gender ";
    $errors ++;

    try this?

  • #3
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb

    Thanks psykx
    unfortunately thats not changed anything, it still snaps to female after submitted.

  • #4
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    is there any code to deal with the input? e.g
    PHP Code:
    if ($_POST['gender'] = "male" )
    {
    male do
    } else {
    female do


  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Your variable $gender is set ... where? Do you have register_globals turned on?

    Other things to nag you about... your <label> tag is inproperly written. You should have two <label> tags enclosing the text "male" and the text "female", and should be for="male" and for="female", with an id="male" and an id="female" inside the input elements.

    Oh and the correct syntax for checking a radio button is checked="checked" rather than the deprecated "checked".

  • #6
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Do you have register_globals turned on?
    If you do, turn it off!

  • #7
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, i found why it was snapping to female- i'm rather embarrassed to say but i had declared $gender = "female"; !!! it was lost in a stack of variables so i missed it- still no excuse for such a sloppy mistake which caused so much sleep loss!
    Thanks for the advice about register_globals i will look into them and bear it in mind next time i get into problems which i bet will be soon
    my project is finished now and it works wonderfully i am very pleased- on with project 2
    Thanks again for helping.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •