For those of you supporting WordPress sites with Contact Form 7, this is a quick customization you can do to make sure that your form submissions provide a little extra information about where the user was previously before accessing your form. Here is the URL of the original post by aravindajith. Unfortunately the original site that was referenced is no longer live, but many thanks to Tony Kwon as well.
- In your Contact Form 7 form, add a Text Field element with a css class referer-page. That will look something like this:
[text referer-page class:referer-page]
- Add the following css to your styles.css
input.referer-page { display:none; }
- Add the following code snippets to your functions.php?
function getRefererPage( $form_tag )
{
if ( $form_tag['name'] == 'referer-page' ) {
$form_tag['values'][] = htmlspecialchars($_SERVER['HTTP_REFERER']);
}
return $form_tag;
}
if ( !is_admin() ) {
add_filter( 'wpcf7_form_tag', 'getRefererPage' );
} - Add the following to the Contact Form 7 Message body (under Mail)
Referer Page: [referer-page]