Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a multisite setup and I am adding some additional information fields in the profile edit screen in my theme's dashboard. I am primarily using text fields however I have a drop down selection menu for the author's country

<select name="country" class="mid2" id="country"  value="<?php echo $userdata->country ?>" style="width:150px;">

My problem is that if a user selects "Togo" for example it registers the change (I know this because it echoes it in the author's bio page) but the default value in the drop down menu (In this case the United States) always stays the same.

Any ideas on how I can have it display whichever country the author has selected?

share|improve this question
    
Let me guess: You hacked the core? –  kaiser Sep 14 '11 at 21:54
    
Nope, no hacking involved (I like to keep my WP installs intact ;]). I'm actually running this through the template using a variation of this code wordpress.org/support/topic/… –  Dean Elliott Sep 14 '11 at 21:59
add comment

2 Answers

up vote 2 down vote accepted

Wordpress has a great little function built in for handling selections.

<option <?php selected('value1', 'value2');?> value='foo'>Bar</option>

You can also check out these form handling functions:

Your HTML syntax is wrong as well. Per W3C, 'value' is not an attribute of the select tag. The value of a select is defined in the options of a select. It should look like this:

<select name="country" class="mid2" id="country" style="width:150px;">
    <option value="US" <?php selected('US', $userdata->country);?>>USA</option>
    <option value="ES" <?php selected('ES', $userdata->country);?>>Spain</option>
    <option value="FR" <?php selected('FR', $userdata->country);?>>France</option>
</select>
share|improve this answer
add comment

So you say it registers the change, so it doesn't really sound like its a Wordpress problem but here is how you would display that anyways.

<option value="your_value" <?php if(this is the Country you selected)echo 'selected="selected"'; ?> >The Country</option> 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.