0

I'm having trouble with this part of my form. I'm not quite sure what's going wrong, so I thought I'd see if anyone here could throw me a hint.

My code is attempting to determine the sex of the user as well as their sexual orientation using only one option. I'm pretty sure this is possible, but I think my syntax is slightly off.

<select name="gender" title="gender" class="dropdown nextPanel <?=( $this->get('error_gender') === true ) ? 'error' : ''?>">
    <option value=""><?php echo $this->localization->get( 'form1.choose' ); ?></option><!-- Text: - - Choose - - -->
    <option value="M" <?=( $_POST['gender']['orientation'] == 'M' . 'F')? 'selected="selected"' : ''?>>Man Seeking a Woman</option>
    <option value="F" <?=( $_POST['gender']['orientation'] == 'F' . 'M')? 'selected="selected"' : ''?>>Woman Seeking a Man</option>
    <option value="M" <?=( $_POST['gender']['orientation'] == 'M' . 'M')? 'selected="selected"' : ''?>>Man Seeking a Man</option>
    <option value="F" <?=( $_POST['gender']['orientation'] == 'F' . 'F')? 'selected="selected"' : ''?>>Woman Seeking a Woman</option>
</select>

I've been crawling documentation but I think I'm overlooking something really small and stupid. I know this one will come easy to someone out there! Thanks for any tips!

3
  • For clarification, when this submits it creates an error, and last I checked, it's outputting nothing at all. Commented Dec 23, 2010 at 18:40
  • Sex and Sexuality aren't binary. Sexuality: en.wikipedia.org/wiki/Kinsey_scale and Gender: en.wikipedia.org/wiki/Third_gender Number of people isn't always 2, either. en.wikipedia.org/wiki/Polyamory Commented Dec 23, 2010 at 18:50
  • Unfortunately the services of the website aren't suited for everybody : ) Commented Dec 23, 2010 at 19:12

4 Answers 4

1
<select name="gender" title="gender" class="dropdown nextPanel <?=( $this->get('error_gender') === true ) ? 'error' : ''?>">
    <option value=""><?php echo $this->localization->get( 'form1.choose' ); ?></option><!-- Text: - - Choose - - -->
    <option value="MF" <?=( $_POST['gender']['orientation'] == 'M' . 'F')? 'selected="selected"' : ''?>>Man Seeking a Woman</option>
    <option value="FM" <?=( $_POST['gender']['orientation'] == 'F' . 'M')? 'selected="selected"' : ''?>>Woman Seeking a Man</option>
    <option value="MM" <?=( $_POST['gender']['orientation'] == 'M' . 'M')? 'selected="selected"' : ''?>>Man Seeking a Man</option>
    <option value="FF" <?=( $_POST['gender']['orientation'] == 'F' . 'F')? 'selected="selected"' : ''?>>Woman Seeking a Woman</option>
</select>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this put me on the right track; I realized I could submit ONE value and then operate on it after submission. I decided to simply go with values 1, 2, 3 and 4. Using a switch, php determines that if 1 is chosen, sex = M and seeking = F. I have no idea what the hell I was trying to do before, haha! Thanks!
1

I think the 'orientation' index is not needed while retrieving values from $_POST. Try this:

<select name="gender" title="gender" class="dropdown nextPanel <?=( $this->get('error_gender') === true ) ? 'error' : ''?>">     
    <option value=""><?php echo $this->localization->get( 'form1.choose' ); ?></option><!-- Text: - - Choose - - -->     
    <option value="M" <?=( $_POST['gender'] == 'M' . 'F')? 'selected="selected"' : ''?>>Man Seeking a Woman</option>     
    <option value="F" <?=( $_POST['gender'] == 'F' . 'M')? 'selected="selected"' : ''?>>Woman Seeking a Man</option>     
    <option value="M" <?=( $_POST['gender'] == 'M' . 'M')? 'selected="selected"' : ''?>>Man Seeking a Man</option>     
    <option value="F" <?=( $_POST['gender'] == 'F' . 'F')? 'selected="selected"' : ''?>>Woman Seeking a Woman</option> 
</select> 

I assume this page is posted back to self.

Comments

0

When this field is POSTED, it will will show up as:

$_POST['gender'] = 'M'

-or-

$_POST['gender'] = 'F'

You cannot tell, from that limited information, what their preference is.

Also, the term $_POST['gender']['orientation'] does not map to a valid array element, because the name of your input field is "gender", not "gender[orientation]".

What you should do is give the <option> tags the following values:

<option value="MF">
<option value="FM">
<option value="MM">
<option value="FF">

Then when you recieve it on the server, you can use array notation:

if($_POST['gender'][0] == 'M')
   // gender is male

if($_POST['gender'][1] == 'F')
   // seeking is female

Does that help?

Comments

0

This should work

<select name="gender" title="gender" class="dropdown nextPanel <?=( $this->get('error_gender') === true ) ? 'error' : ''?>">
    <option value=""><?php echo $this->localization->get( 'form1.choose' ); ?></option><!-- Text: - - Choose - - -->
    <option value="MF" <?=( $_POST['gender'] == 'MF')? 'selected="selected"' : ''?>>Man Seeking a Woman</option>
    <option value="FM" <?=( $_POST['gender'] == 'FM')? 'selected="selected"' : ''?>>Woman Seeking a Man</option>
    <option value="MM" <?=( $_POST['gender'] == 'MM')? 'selected="selected"' : ''?>>Man Seeking a Man</option>
    <option value="FF" <?=( $_POST['gender'] == 'FF')? 'selected="selected"' : ''?>>Woman Seeking a Woman</option>
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.