• designreaction

    (@designreaction)


    I have used the following code on my theme functions.php to create 2 new form fields for users to enter a phone number and their company name on their user profile, which works perfect:

    add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
    add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
    function my_show_extra_profile_fields( $user ) { ?>
    <table class="form-table">
    <tr>
                <th><label for="phone">Phone Number</label></th>
                <td>
                <input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br />
                </td>
    </tr>
    	<tr>
                <th><label for="phone">Referral Agency</label></th>
    	        <td>
                <input type="text" name="companyname" id="companyname" value="<?php echo esc_attr( get_the_author_meta( 'companyname', $user->ID ) ); ?>" class="regular-text" /><br />
                </td>
    </tr>
    </table>
    <?php }
    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;
    update_usermeta( $user_id, 'phone', $_POST['phone'] );
    update_usermeta( $user_id, 'companyname', $_POST['companyname'] );
    }

    Back on Contact Form 7, I pull in the standard usermeta for the logged in user’s first name successfully using:

    [text first-name default:user_first_name placeholder "First Name"]

    But I am also trying to find a way to pull in the custom user meta for the new telephone and company name, sadly the following doesn’t work:

    [text telephone default:user_phone placeholder "Telephone"]
    [text company-name default:user_companyname placeholder "Company Name"]

    Does anyone have any experience in creating custom user profile fields and calling these in to default form fields with contact form 7?

    Thanks in advance.

  • The topic ‘calling usermeta to autofill fields’ is closed to new replies.