field298 Single Line Text Box
Instead of free input I wanted to show a select dropdown to validate input. There were a ton of options, so I created an array, and then looped through the array to create the <options>. A first blank option was also added.
Template
PHP Code:
<select class="primary" name="userfield[field298]" id="cfield_298" tabindex="1">
<option value="" <vb:if condition="$bbuserinfo['field298'] == ''">selected="selected"</vb:if> ></option>
<vb:each from="titlearray[$allcharacterdb[$bbuserinfo['field109']]['Organization']]" key="userid" value="userinfo">
<option value="{vb:raw userinfo.title}" <vb:if condition="$bbuserinfo['field298'] == '{vb:raw userinfo.title}'">selected="selected"</vb:if> >{vb:raw userinfo.title}</option>
</vb:each>
</select>
HTML Output (small sampling)
HTML Code:
<select class="primary" name="userfield[field298]" id="cfield_298" tabindex="1">
<option value=""></option>
<option value="Adept">Adept</option>
<option value="Axesworn">Axesworn</option>
</select>
So this all works, and saves fine. The problem is that the
selected attribute isn't catching on the option/field after it's been saved and then the form is brought up again. So the next time the form pulls up, it's blank, and then clears the field. Here's where I'm trying to set the attribute. What am I missing?
PHP Code:
<vb:if condition="$bbuserinfo['field298'] == '{vb:raw userinfo.title}'">selected="selected"</vb:if>