WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Contact Form 7] Auto-display username in contact form (9 posts)

  1. nomadweb
    Member
    Posted 4 years ago #

    Hi,
    I would like to auto-display currently logged-in username (of the user who sends message) in the contact form, also visible in field when sent as HTML content type e-mail.

  2. nomadweb
    Member
    Posted 4 years ago #

    I've tried different codes but just can't get it. Anybody?

  3. revivetv
    Member
    Posted 4 years ago #

    Me too. Any luck on this?

    Have also tried to display username in the body of a page page with

    <?php global $current_user; if ( isset($current_user) ) { echo $current_user->user_login; } ?>

    ... as suggested on other threads. Have tried multiple variations including moving the parentheses, but it doesn't work. All I get this displayed on the page:

    user_login; }?>

    Which makes me think the "->" is being read as closing the php tag...

    Help!

  4. revivetv
    Member
    Posted 4 years ago #

    Found a solution:

    Used the PHP Execution plugin, which enables you to insert php code directly into posts and pages.

    Then used this in the HTML view of a page to display the username:

    <?php global $current_user; if ( isset($current_user) ) { echo $current_user->user_login; } ?>

    This helps me, but still curious about how to display the username by default in the contact form.

  5. fuzzie
    Member
    Posted 3 years ago #

    This helps me, but still curious about how to display the username by default in the contact form.

    Same here...and email address

  6. fuzzie
    Member
    Posted 3 years ago #

    I figured it out:

    <?php global $current_user; if ( isset($current_user) ) {
    echo 'User: ' . $current_user->user_login . '
    ' .
    'Email: ' . $current_user->user_email;
    ?>
    [contact-form 3 "Contact Form 1 - registered users"]

    <?php } else { ?>
    [contact-form 1 "Contact form 1"]
    <?php } ?>

  7. fuzzie
    Member
    Posted 3 years ago #

    I changed it a little:

    <?php global $current_user; if( is_user_logged_in() ) {
    echo 'User: ' . $current_user->user_login . '
    ' .
    'Email: ' . $current_user->user_email;
    ?>
    [contact-form 3 "Contact Form 1 - registered users"]

    <?php } else { ?>
    [contact-form 1 "Contact form 1"]
    <?php } ?>

    if( is_user_logged_in() ) instead.

  8. rmkbow
    Member
    Posted 3 years ago #

    How did you setup the contact form so that the emails would contain the username and email?

  9. Elliot_Sowersby
    Member
    Posted 3 years ago #

    @rmkbow i need that too, did you work it out?

Topic Closed

This topic has been closed to new replies.

About this Topic