Contact Form 7
Trick to include PHP in the form fields? (4 posts)

  1. Adam Capriola
    Posted 5 years ago #

    I've tried doing this, but with no success, so I thought I'd see if anyone else knows how to do it.

    Basically I want to include PHP as the value within some of the form fields so that I can pre-fill information, like the user's name and e-mail when they are logged in to my site.

    I tried this: [text text-411 "<?php if ( is_user_logged_in() ) { ?><?php global $current_user; get_currentuserinfo(); echo $current_user->user_email; ?><?php } ?>"]

    But the form showed all the PHP code there and not my e-mail. I also had the Exec PHP plugin turned on so that PHP should run in pages/posts.

    Any ideas on how to make this work? Thanks so much in advance!


  2. WiSch
    Posted 5 years ago #

    For the username maybe this can help you out?

    For some other dynamic Text maybe this PlugIn is for you?

  3. Adam Capriola
    Posted 5 years ago #

    Not quite. :(

    The first link will output a username or e-mail, but not prefill a field.

    The second one doesn't seem to have the right capability either. It can only get limited stuff.

  4. WiSch
    Posted 5 years ago #

    I know that's no prefill but if you need the mail or username...

    For a prefill I saw only (somewhere here in the forum) a solution via JavaScript in a own template in combination with a given name/id for the target-field in the form.

    No solution for an included way to prefill the fields...

    If you found a way, please post it here, thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic