Selected option in Opencart
I am making a modification to my Opencart registration page (register.tpl)
by adding a list of security questions for the user to select one before
registering.
What I am trying to do is to have the previously selected item be selected
again on postback (if user makes an error on the page).
My code so far is
<tr>
<td><span class="required">*</span> <?php echo
$entry_security_question; ?></td>
<td><select name="security_question">
<option value=""> - Select a question - </option>
<option value="<?php echo $security_question1 ?>" <?php
if(isset($this->request->post['security_question'])==$security_question1){echo
"selected";}?>><?php echo $security_question1 ?></option>
<option value="<?php echo $security_question2 ?>" <?php
if(isset($this->request->post['security_question'])==$security_question2){echo
"selected";}?>><?php echo $security_question2 ?></option>
<option value="<?php echo $security_question3 ?>" <?php
if(isset($this->request->post['security_question'])==$security_question3){echo
"selected";}?>><?php echo $security_question3 ?></option>
</select>
<?php if ($error_security_question) { ?>
<span class="error"><?php echo $error_security_question;
?></span>
</td>
</tr>
However, what this seems to do is apply "selected" to all the options in
the dropdownlist. How do I get this done?
No comments:
Post a Comment