• Resolved blurryfish

    (@photonatic)


    Hi.

    I’ve followed the short tutorial [1] on adding new custom fields successfully. For my purpose I’ve added First Name, Last Name (in the same manner as described in the tutorial) and Address. The last field is added as a <textarea> instead of <input> in the custom register-form.php and profile-form.php.

    I don’t have problem seeing the inserted values in First Name, Last Name and Address in the Profile page. However, upon editing the value in Address and submitting the form won’t update its value in the database; all other fields are updated as expected.

    What I’ve tried:

    1) Added the attribute form=”your-profile” to my <textarea>, hoping the submit button would pick up the fresh content in it.
    2) Changed <textarea> back to <input> (like First Name and Last Name) in profile-form.php.
    3) Added hook ‘edit_user_profile_update’ in theme-my-login-custom.php with the following code:

    function tml_user_profile_update( $user_id ) {
    wp_die ( “Fired!” );

    if ( current_user_can(‘edit_user’, $user_id) )
    update_user_meta($user_id, ‘tml_address’, $_POST[‘tml_address’]);
    }

    add_action(‘edit_user_profile_update’, ‘tml_user_profile_update’);

    The hook is never fired, even if I move it into the theme’s functions.php instead.

    Can anyone shed some light on this?

    [1] Adding Extra Registration Fields – Theme My Login Documentation
    https://docs.thememylogin.com/adding-extra-registration-fields/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jeff Farthing

    (@jfarthing84)

    Did you actually read step 3 of the tutorial you referenced?

    Thread Starter blurryfish

    (@photonatic)

    Hi.

    Your third step does not seem to deal with updating meta data fields.

    For anyone interested I made it work by adding an action to the hook ‘personal_options_update’.

    Thanks.

    Here is my solution to the problem of adding fields to Theme-My-Login registration form

    1) add the code to the file functions.php rename the existing WordPress fields to the ones we need

    add_filter('user_contactmethods', '_my_get_user_contactmethods');
    function _my_get_user_contactmethods() {
        $user_contactmethods = array(
            'appartment' => __('Numéro de votre appartement'),
            'basement_number' => __('Numéro de cave, le cas échéant')
        );
        return $user_contactmethods;
    }

    2) in the file register-form.php add the output of fields

    <label for="appartment<?php $template->the_instance(); ?>"><?php _e( 'Numéro de appartemen', 'theme-my-login' ) ?></label>
            	<input type="text" name="appartment" id="appartment" class="input" value="<?php echo $_POST['appartment']; ?>" size="15" tabindex="20" />
                  
            	<label for="basement_number<?php $template->the_instance(); ?>"><?php _e( 'Numéro de chambre au sous-sol', 'theme-my-login' ) ?></label>
            	<input type="text" name="basement_number" id="basement_number" class="input" value="<?php echo $_POST['basement_number']; ?>" size="15" tabindex="20" />

    3)in the file functions.php will check for errors the entered data by the user and update the user data :

    add_action('register_post','check_fields',10,3);
    add_action('user_register', 'register_fields');
    
    function check_fields ( $login, $email, $errors ) {
    global $appartment, $basement_number;
    if ($_POST['appartment'] == ''){
    $errors->add( 'empty_realname', "<strong>ERREUR</strong>: Indiquez le numéro de votre appartment!" );
    } else {
    $appartment = $_POST['appartment'];
    }
    if ($_POST['basement_number'] == ''){
    $errors->add( 'empty_realname', "<strong>ERREUR</strong>: Indiquez votre numéro de cave, le cas échéant" );
    }
    else {
    $basement_number = $_POST['basement_number'];}
    }
    function register_fields($user_id,$password= "",$meta=array()){
    update_user_meta( $user_id, 'appartment', $_POST['appartment'] );
    update_user_meta( $user_id, 'basement_number', $_POST['basement_number'] );
    }
    • This reply was modified 7 years, 11 months ago by kalammitta.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem updating custom field in TML Profile’ is closed to new replies.