Support

Account

Home Forums Front-end Issues Update field in user registration form

Solved

Update field in user registration form

  • I’ve added the field supplier_user_description to ACF in the user roles, and I’m trying to update that info when a user registers with the field key, but it’s not working.
    <?php $user = update_field( 'field_6004677a93a7f', $supplier_description );?>

    This is the field html:

    <label>Supplier Description <span class="error">*</span></label>
    <input type="text" name="supplier-description" class="text" placeholder="Enter Your Supplier Description" required />

    This grabs the field values input by the user:

    <?php global $reg_errors;
        $reg_errors = new WP_Error;
        $supplier_description=$_POST['supplier-description'];

    This is on my custom registration form:

    if ( 1 > count( $reg_errors->get_error_messages() ) )
        {
            // sanitize user form input
            global $username, $useremail;
            $username   =   sanitize_user( $_POST['username'] );
            $useremail  =   sanitize_email( $_POST['useremail'] );
            $password   =   esc_attr( $_POST['password'] );
            $role       =   'Supplier';
            
            $userdata = array(
                'user_login'    =>   $username,
                'user_email'    =>   $useremail,
                'user_pass'     =>   $password,
                'role'          =>   $role,
                );
            $user = update_field( 'field_6004677a93a7f', $supplier_description );
            $user = wp_insert_user( $userdata );
        }
  • How is there a post ID if I’m registering a new user? Isn’t the ID created when the user is?

  • 
    $user = wp_insert_user( $userdata );
    

    returns the user ID. Update fields after this.

  • Running
    $user = update_field( 'field_6004677a93a7f', $supplier_description, '$user_{$user_ID}' );

    after
    $user = wp_insert_user( $userdata );

    Seems to break the user registration. Is running the update against the $user variable the best way of updating the ACF field?

    Thanks for your help by the way, this is most excellent of you.

  • 
    $user = wp_insert_user( $userdata );
    update_field('field_6004677a93a7f', $supplier_description, 'user_'.$user);
    
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.