Extra User Field on Register Page

This topic contains 10 replies, has 4 voices, and was last updated by  Dotty Directory 8 years, 10 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #160107

    EH
    Expired Member
    Post count: 96

    Is it possible to ask for Company Name on the register page?

    #160201

    Paolo
    Site Admin
    Post count: 31211

    hi,

    I asked the developer to check if there is a filter (I believe there is) and how to use it.

    Thanks

    #160245

    EH
    Expired Member
    Post count: 96

    Thank you!

    #160809

    Giri
    Expired Member
    Post count: 3155

    Please use this code in your child theme’s functions.php file

    
    
    function whoop_add_signup_form_fields() {
        ?>
        <div class="row_spacer_registration clearfix">
            <div class="form_row clearfix">
                <input placeholder='Company Name' type="text" name="company"
                       id="company" class="textfield input-text" value="" size="25"/>
                <span id="company_info"></span>
            </div>
        </div>
        <?php
    }
    add_action('social_connect_form', 'whoop_add_signup_form_fields', 1);
    
    function whoop_check_signup_form_errors($errors) {
        $company = esc_sql(sanitize_text_field($_POST['company']));
        if ($company == '') {
            $errors->add('empty_company', __('ERROR: Please enter your company name.', 'geodirectory'));
        }
        return $errors;
    }
    add_filter('registration_errors', 'whoop_check_signup_form_errors');
    
    function whoop_insert_signup_extra_fields($user_id) {
        $company = esc_sql(sanitize_text_field($_POST['company']));
        update_user_meta($user_id, 'company', $company);
    }
    add_action('geodir_user_register', 'whoop_insert_signup_extra_fields');
    
    add_action( 'show_user_profile', 'whoop_extra_profile_fields' );
    add_action( 'edit_user_profile', 'whoop_extra_profile_fields' );
    
    function whoop_extra_profile_fields( $user ) { ?>
    
    	<h3>Extra profile information</h3>
    
    	<table class="form-table">
    
    		<tr>
    			<th><label for="company">Company</label></th>
    
    			<td>
    				<input type="text" name="company" id="company" value="<?php echo esc_attr( get_the_author_meta( 'company', $user->ID ) ); ?>" class="regular-text" /><br />
    				<span class="description">Please enter your Company name.</span>
    			</td>
    		</tr>
    
    	</table>
    <?php }
    
    add_action( 'personal_options_update', 'whoop_save_extra_profile_fields' );
    add_action( 'edit_user_profile_update', 'whoop_save_extra_profile_fields' );
    
    function whoop_save_extra_profile_fields( $user_id ) {
    
    	if ( !current_user_can( 'edit_user', $user_id ) )
    		return false;
    
    	update_user_meta( $user_id, 'company', $_POST['company'] );
    }
    #161500

    EH
    Expired Member
    Post count: 96

    Thank you worked perfectly.

    #161501

    Giri
    Expired Member
    Post count: 3155

    You are welcome 🙂

    #191987

    Dotty Directory
    Full Member
    Post count: 254

    I’ve tried adding this to my site and it didnt work, is this specifically for Whoop theme? I’m not using a theme.

    I’m just trying to add Username field to the registration form.

    Thanks

    #191992

    Giri
    Expired Member
    Post count: 3155

    Dotty, code posted above most likely work with other themes too. Fields will be appear in geodirectory registration page. make sure you posted above code in your child theme.

    #191995

    Dotty Directory
    Full Member
    Post count: 254

    I have done that now and it is showing, is there a way to bring it to the top of the form and for it to be a username function ? The form is still identifying email address as username

    Thanks

    #192971

    Giri
    Expired Member
    Post count: 3155

    I’m sorry but the email is used as username

    that could possibly be done, but would require time to study the customization and this goes beyond support

    #193419

    Dotty Directory
    Full Member
    Post count: 254

    Not a problem Giri, its something we can live with! 🙂

    Thank you for your respone

Viewing 11 posts - 1 through 11 (of 11 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount