Skip to:
Content
Pages
Categories
Search
Top
Bottom

Include custom wordpress field in registration


  • chriotte
    Participant

    @chriotte

    Hi,
    I would like users to submit phone number on registration and automatically save it in a WordPress field.This should be only visible for admins, and therefore, the xProfile fields won’t work. To create a user the user fill out this form with password and email (Username is created programmatically).
    Registration
    I would like the phone number field there as well, but I’m not sure how to update the field at submission.
    I tried to add the field with this code: <input type="text" name="phone" id="phone" value="" class="regular-text" <?php bp_form_field_attributes('phone'); ?>
    But the field is blank when I check in WP admin. Any idea how I can do this?

    If i click to edit a user in WP admin I want the number to be added to this field.
    field in wp admin
    I followed a tutorial to create the field, and added it to my function file with this code:

    add_action( ‘show_user_profile’, ‘my_show_extra_profile_fields’ );
    add_action( ‘edit_user_profile’, ‘my_show_extra_profile_fields’ );
    function my_show_extra_profile_fields( $user ) { ?>
    <h3>Extra profile information</h3>
    <table class=”form-table”>
    <tr>
    <th><label for=”phone”>Telefon</label></th>
    <td>
    <input type=”text” name=”phone” id=”phone” value=”<?php echo esc_attr( get_the_author_meta( ‘phone’, $user->ID ) ); ?>” class=”regular-text” /><br />
    <span class=”description”>Vennligst angi ditt telefonummer slik ati </span>
    </td>
    </tr>
    </table>
    <?php }

    add_action( ‘personal_options_update’, ‘my_save_extra_profile_fields’ );
    add_action( ‘edit_user_profile_update’, ‘my_save_extra_profile_fields’ );

    function my_save_extra_profile_fields( $user_id ) {

    if ( !current_user_can( ‘edit_user’, $user_id ) )
    return false;

    update_usermeta( $user_id, ‘phone’, $_POST[‘phone’] );
    }`

Viewing 2 replies - 1 through 2 (of 2 total)

  • chriotte
    Participant

    @chriotte

    This is how it looks on the front end with the input added to my code.
    field
    (Telefon = Phone)
    I simply need som guidance on how to update user_meta on buddypress registration submit.


    chriotte
    Participant

    @chriotte

    Some trying and failing with the help of google gave me the answer.

    // Add field_name from sign-up to usermeta on registration
    function bp_user_activate_field( $signup ) {
    
    	$bpCustomField = $_POST['phone'];
    	
    	update_usermeta( $signup, 'phone', $bpCustomField );
    	
    	return $signup;
    }
    add_filter( 'user_register', 'bp_user_activate_field' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Include custom wordpress field in registration’ is closed to new replies.
Skip to toolbar