add new fields on registration page

I have a wordpress website, and I want to add new fields when user register, like phone number and street address.

I know how to add input fields in registration form, but I cannot understand how to save this fields in database during registration, like other details as username are saved.

Read More

How to do that?

UPDATE:

add_action('user_register', 'myplugin_user_register')

the function myplugin_user_register() is called after main user details like username, email was inserted in database, or all details will be saved at same time.

I also want to save extra fields in other table, in $wpdb->users, how to do this ?

Related posts

Leave a Reply

3 comments

  1. In case you do not want to dip into code yourself, there are a few very simple plugins that will do the job for you like : cimy user extra fields or User Registration Aide..

    You could search more at the same place ( Plugin repository )

    Regarding your Update :

    what you should use is update_user_meta() , add_user_meta(), delete_user_meta() and get_user_meta() , all of which act exactly like the post_meta ( custom fields ) with the sole difference that they are assigned to users instead of post . think of them like “custom fields for users”

    and just like RafH said , there is no need to add tables, and actually it is a bad practice when working with wordpress, and a receipt for future headaches.

  2. user_register action hook is used to save the extra field data to database as user meta submitted by custom registration forms.Basically , when a new user is created ,the user id is passed to this action hook as argument and used to save the extra field in user meta.

    add_action( 'user_register', 'my_save_extra_fields', 10, 1 );
    
    function my_save_extra_fields( $user_id ) {
    
        if ( isset( $_POST['mobile_no'] ) )
            update_user_meta($user_id, 'mobile_no', $_POST['mobile_no']);
    
    }