Title: Extra registration fields -&gt; Into database?
Last modified: August 31, 2016

---

# Extra registration fields -> Into database?

 *  [gotu1](https://wordpress.org/support/users/gotu1/)
 * (@gotu1)
 * [10 years ago](https://wordpress.org/support/topic/extra-registration-fields-into-database/)
 * Below you see a screenshot and the code, I must have done something wrong as 
   you can see in the database screenshot, the values of the extra fields are not
   added in the database, looks like there’s no contact ^^,
 * Does anyone have any clue what a codenoob like me have messed up? =)
 * [How it looks](https://i.imgur.com/57oHza1.jpg)
    [Database – nothing sadface](https://i.imgur.com/zAFM2GL.jpg)**
   Code added in functions.php**
 *     ```
       add_action( 'register_form', 'myplugin_register_form' );
       function myplugin_register_form() {
   
           $user_fname = ( ! empty( $_POST['user_fname'] ) ) ? trim( $_POST['user_fname'] ) : '';
           $user_lname = ( ! empty( $_POST['user_lname'] ) ) ? trim( $_POST['user_lname'] ) : '';
           $user_phone = ( ! empty( $_POST['user_phone'] ) ) ? trim( $_POST['user_phone'] ) : '';
   
               ?>
               <p>
                   <label for="user_fname"><?php _e( 'First Name', 'mydomain' ) ?><br />
                       <input type="text" name="user_fname" id="user_fname" class="input" value="<?php echo esc_attr( wp_unslash( $user_fname ) ); ?>" size="25" /></label>
               </p>
               <p>
                   <label for="user_lname"><?php _e( 'Last Name', 'mydomain' ) ?><br />
                       <input type="text" name="user_lname" id="user_lname" class="input" value="<?php echo esc_attr( wp_unslash( $user_lname ) ); ?>" size="25" /></label>
               </p>
               <p>
                   <label for="user_phone"><?php _e( 'Mobile Number', 'mydomain' ) ?><br />
                       <input type="text" name="user_phone" id="user_phone" class="input" value="<?php echo esc_attr( wp_unslash( $user_phone ) ); ?>" size="25" /></label>
               </p>
               <?php
           }
   
           //2. Add validation. In this case, we make sure user_fname is required.
           add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
           function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
   
               if ( empty( $_POST['user_fname'] ) || ! empty( $_POST['user_fname'] ) && trim( $_POST['user_fname'] ) == '' ) {
                   $errors->add( 'user_fname_error', __( '<strong>ERROR</strong>: You must include a first name.', 'mydomain' ) );
               }
               if ( empty( $_POST['user_lname'] ) || ! empty( $_POST['user_lname'] ) && trim( $_POST['user_lname'] ) == '' ) {
                   $errors->add( 'user_lname_error', __( '<strong>ERROR</strong>: You must include a last name.', 'mydomain' ) );
               }
               if ( empty( $_POST['user_phone'] ) || ! empty( $_POST['user_phone'] ) && trim( $_POST['user_phone'] ) == '' ) {
                   $errors->add( 'user_phone_error', __( '<strong>ERROR</strong>: You must include a mobile number.', 'mydomain' ) );
               }
   
               return $errors;
           }
   
           //3. Finally, save our extra registration user meta.
           add_action( 'user_register', 'myplugin_user_register' );
           function myplugin_user_register( $user_id ) {
               if ( ! empty( $_POST['user_fname'] ) ) {
                   update_user_meta( $user_id, 'user_fname', trim( $_POST['user_fname'] ) );
               }
               if ( ! empty( $_POST['user_lname'] ) ) {
                   update_user_meta( $user_id, 'user_lname', trim( $_POST['user_lname'] ) );
               }
               if ( ! empty( $_POST['user_phone'] ) ) {
                   update_user_meta( $user_id, 'user_phone', trim( $_POST['user_phone'] ) );
               }
           };
       ```
   

The topic ‘Extra registration fields -> Into database?’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [extra fields](https://wordpress.org/support/topic-tag/extra-fields/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [gotu1](https://wordpress.org/support/users/gotu1/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/extra-registration-fields-into-database/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
