• 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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter nomadweb

    (@nomadweb)

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

    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!

    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.

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

    Same here…and email address

    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 } ?>

    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.

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

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Contact Form 7] Auto-display username in contact form’ is closed to new replies.