I am using a captcha in a form. When the user submits an invalid answer to the captcha, the page reloads repopulating the fields with the user data. My question is, is there a better (or easier) way to check which dropdown value was selected.
This is what I have now that works:
php
<?php
$state = $sf_params->get('state');
?>
html
<span>State </span>
<select size="1" name="state">
<option value="" selected="selected"></option>
<option value="AL" <?php if ($state == "AL") { echo "selected = 'selected'"; } ?>>Alabama</option>
<option value="AK" <?php if ($state == "AK") { echo "selected = 'selected'"; } ?>>Alaska</option>
<option value="AZ" <?php if ($state == "AZ") { echo "selected = 'selected'"; } ?>>Arizona</option>
<option value="AR" <?php if ($state == "AR") { echo "selected = 'selected'"; } ?>>Arkansas</option>
Is there another solution to getting the GET variable, then parsing the options, looking for the matched value?
First move the values of the select to an array in the Controller like
Then you can use the Helper j0k mentioned or go by feet:
By assigning the vars in the controller.
In the Template:
But I also recommend to use the Helper.