Jump to content

Options based on member gender

- - - - -

  • Please log in to reply
2 replies to this topic

#1
mexico_way

mexico_way

    Newbie

  • Members
  • Pip
  • 2 posts
I have 2 different drop down forms based on if the member is male or female and I need only that form to show. Like if you are viewing a male members profile, you would see the form that has the options for male and if you are viewing a female members profile, you would see the form that has the options for female. I'm not exactly sure how to accomplish this but here's what I have as the general idea:


<?php 

// ------- Start Forms-------------------

$male_options = "<form name="form1" method="post" action="profile.php">

                 <select name="male_options" id="male_options">

                 <option>Option 1</option>

                 <option>Option 2</option>

                 </select>

				 <input type="submit" name="button" id="button" value="Send">

				 </form>";

$female_options = "<form name="form2" method="post" action="profile.php">

                   <select name="female_options" id="female_options">

                   <option>Option 1</option>

                   <option>Option 2</option>

                   </select>

				   <input type="submit" name="button" id="button" value="Send">

				   </form>";

// ------- End Forms-------------------

?>

And here is the part where I need to echo the form out:

<?php 

		  $gender = $row["gender"]; 

          if ($gender=="male")

          echo "$male_options";

          else

          echo "$female_options"; ?>


#2
Mark Wylde

Mark Wylde

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
You have two options for how to do this. The first is to use jQuery, or the second is two have two forms.

Are you willing to use jQuery/Javascript to do this?

If not you will need to create the first page which you will select male/female, then you can use the $_POST["gender"] variable to get what the gender is.

#3
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 554 posts
  • Location:/etc/passwd
Wait if you know the gender before the page is generated then the code you have is fine (through it may be buggy).
If you find the gender out after the page loads the best choice is to do something like this:
Have a option form of male or female.
Have a div area called say genderOption. This starts out with the menu(s) for the default gender.

When the gender is changed a Javascript function uses AJAX (this is not a plugin/library simply a method) to contact a PHP page called say genderChoose.php it requests genderChoose.php?g=[male/female] when it gets the result it sets the genderOption div to what ever the result is.

Just google AJAX W3C has a great tut on it (its actually really easy!).

The PHP code simply displays the menu depending on the GET variables (the stuff after .php?) as if it was a barely formatted page- Javascript will request this data and insert it into the div area without the page reloading (of course it contacts the server but the page doesn't vanish just the div box changes).
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users