• hi.
    i did create a new profile field (custom user_meta), with help of this code:

    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;
    	/* Copy and paste this line for additional fields. */
            add_user_meta( $user_id, ‘person_relation’, 30318 );
    	update_user_meta( $user_id, 'person_relation', $_POST['person_relation'] );
    }

    and added a column to view it in my dashboard (users page)

    i have a sign up page, which uses POST method.
    so, i created a place for users to fill the information i needed with this code:

    <tr>
    <th><label for="person_relation">Inviter's Name</label></th>
    <td>
    <input type="text" name="person_relation" id="person_relation" value="<?php echo esc_attr( get_the_author_meta( 'person_relation', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description">Please enter your inviter's name.</span>
    </td>
    </tr>

    BUT when the user click on “Complete sign up”.
    the info i want, is returning null! nothing is in it! 😐
    and i have to ask my users again! to tell me the info, so i can enter it manually from dashboard->users->edit->…

    how can i recieve that user_meta from the registration form (i mean when the
    users complete their sign up and push the button)?
    do i need to add something? how?
    any help would be appreciated.

    tnx a lottt.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello Masoud,

    If you want to add some user meta info in user database while registration you need to use “user_register” filter like below code:Add code in your themes function.php file

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

    Thanks

    Thread Starter Masoud

    (@masoud1111)

    hi. the code worked like a charmmm. tnx a lottttttt. u made my day 🙂
    i placed the code and add necessary changes to it like:

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

    just one more question, if you dont mind.

    how can i make this, a must fill information field??
    i mean just like email (you have to provide an email to register), right?
    i want to make my custom field just like email (a must fill info field)
    so if a user leave that field empty, an error apears (please fill it)
    and if not empty[spaces, commas or… not accepted](at least 3 or 4 words length), then continue the registeration process.

    i’d be grateful if you help me with this one too.
    tnx.

    Thread Starter Masoud

    (@masoud1111)

    @clarionwpdeveloper
    sorry. but forgot to mention this.
    this field maybe in RTL language (i mean not only english)
    i’ve found something like these:
    (1)

    if(preg_match('/^[a-zA-Z0-9]{5,}$/', $username))
    { // for english chars + numbers only
      // valid username, alphanumeric & longer than or equals 5 chars
    }

    (2)

    if ( !preg_match('/^[A-Za-z][A-Za-z0-9]{5,31}$/', $joinUser) )
    {...
    }

    but i have no idea
    1) how to use it?
    2) how can i refer my custom user meta to be checked with these?

    tnx for helping me.

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

The topic ‘registration page help’ is closed to new replies.