I'm customizing the WordPress registration form, and I need to display an list of options from a select on form submission.

I was using the following code to capture the selected option of the select:

<option value="Medicine" id="option-1" <?php if($_POST['name_of_select']=='Medicine') {?> selected="selected" <?Php } ?>>Medicine</option>

Here's a jQuery code to generate the list:

function list(array_list) {

    $("#formOptions").html(""); //reset child options
    $(array_list).each(function (i) { //populate child options
        $("#formOptions").append("<option value=\""+array_list[i].value+"\">"+array_list[i].display+"</option>");


And the options of list:

var Option 1 = [
    {display: "Medicine", value: "Medicine" }];

Since the list is loaded according to another option previously selected.

Now I'm using jQuery to generate the list of options select field. But when user send a form, the value of the selected option does not sent. The option is sent blank.

My question is:

How do I capture the selected option and pass in sending the registration form?

I appreciate any tip

1 Answer 1


Way use jQery to populate the select field when you can use filter and hook into the form using PHP eg:

 //1. Add a new form element...
function _register_form_wpa103118 (){
    $name_of_select = ( isset( $_POST['name_of_select'] ) ) ? $_POST['name_of_select']: '';
    $options = array(
        'Medicine' => 'Medicine',
        'Option2' => 'Option2',
        <label for="name_of_select"><?php _e('First Name','mydomain') ?><br />
            <select name="name_of_select">
                foreach ($options as $key => $value) {
                    $selected = ($value == $name_of_select)? ' selected="selected"': '';
                    echo '<option'.$selected.' value="'.$key.'">'.$value.'</option>';

//2. Add validation. In this case, we make sure first_name is required.
add_filter('registration_errors', '_registration_errors_wpa103118', 10, 3);
function _registration_errors_wpa103118 ($errors, $sanitized_user_login, $user_email) {
    if ( empty( $_POST['name_of_select'] ) )
        $errors->add( 'name_of_select', __('<strong>ERROR</strong>: You must select ....') );

    return $errors;

//3. Finally, save our extra registration user meta. or do whatever you want with it.
add_action('user_register', '_user_register_wpa103118');
function _user_register_wpa103118 ($user_id) {
    if ( isset( $_POST['name_of_select'] ) )
        update_user_meta($user_id, 'name_of_select', $_POST['name_of_select']);
  • Hi, Thank you Bainternet, is good tip. But, I need to display two select, and the secundary select is populated according the first option selected. For this, I used jQuery. The question is that, I do not get the option selected when the form is submited.
    – Enoque
    Jun 16, 2013 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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