Reputation: 2837
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!
Upvotes: 0
Views: 758
Reputation: 6571
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>
Upvotes: 0
Reputation: 137322
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?
Upvotes: 0
Reputation: 82913
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.
Upvotes: 1
Reputation: 3634
<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>
Upvotes: 1