The MU forums have moved to WordPress.org

How to add an extra field to signup form? (3 posts)

  1. vimaljoseph
    Member
    Posted 14 years ago #

    I want to write a plugin for my wpmu installation to add an extra text field to the default signup form. I've tried Cimy User Extra Fields plugin. But It is too heavy for my use and I dont want to save that information to the db.

    I'm new to wordpress development. Please help me find the right filter/action? Or point me to some code samples.

    thanks

  2. vimaljoseph
    Member
    Posted 14 years ago #

    Hi,

    I solved my problem with the following action and filters

    //add the extra fields here
    add_action('signup_extra_fields', 'my_extra_field');
    //validate the extra field
    add_filter('wpmu_validate_user_signup', 'my_validation');
    //capture the data and add it to the $meta array. You can use the captured data where ever $meta array is available.
    add_filter('add_signup_meta','my_add_signup_meta');
    //pass the extra fields as hidden fields to the blog registration form
    add_filter('signup_blogform', 'my_extra_fields_pass_through');
    
    function my_extra_field($errors) {
    $error = $errors->get_error_message('error-tag');
    ?>
    <label for="password"><?php _e('Title'); ?>:</label>
    <textarea name="name-of-field" type="text" rows="5" wrap="soft" id="id_content"/></textarea>
    <?php
    if($error) {
    echo '<p class="error">' . $error . '</p>';
    }
    ?>
    
    <?php
    }
    
    function my_validation($content) {
    $data = $_POST['name-of-field'];
    if($data == '' && $_POST['stage'] == 'validate-user-signup') {
    $content['errors']->add('error-tag', __('You should enter the this data to signup.'));
    }
    return $content;
    }
    
    function my_signup_meta($meta) {
    $data = $_POST['name-of-field'];
    $add_meta = array('meta-tag' => $data);
    $meta = array_merge($add_meta, $meta);
    return $meta;
    }
    
    function my_extra_fields_pass_through() {
    
    if (!empty( $_POST['name-of-field'] )){
    
    ?>
    
    <input type="hidden" name="name-of-field" value="<?php echo $_POST['name-of-field']; ?>" />
    
    <?php
    }
    
    }

    thanks to the authors of different plugins available for wpmu from which i got clues and examples to solve this. :)

  3. jlm99
    Member
    Posted 14 years ago #

    @vimaljoseph thanks for posting this. i'm working on adding extra fields to our site's registration too. one question -- i was assuming i'd need to pass the "meta" array from wp_signups to wp_usermeta so i can call the extra fields in profile pages, tables in the backend for site admin to see all the info, etc. i was going to hook to user_register and use update_usermeta.

    but you don't do this -- how are you displaying the info from your new fields? just curious if i'm missing an easier way.

About this Topic

  • Started 14 years ago by vimaljoseph
  • Latest reply from jlm99