Adding Visitor IP and Current Page to “Contact Form 7″ Wordpress Plugin
Make sure to get FREE DIY SEO link packages Vince's Links
I’ve loved using the Contact Form 7 Wordpress Plugin so far, but it was missing two VITAL features:
I was unable to send the visitors IP address with the form submission, and I was unable to tell which exact page the form submission came from if I was using the form on more than one page.
Here is a fix for both of those little short falls:
Edit the plugin - You can do this through the wordpress plugin editor http://YOUR-DOMAIN-NAME/wp-admin/plugin-editor.php
Paste the following code just above the last line of code - The last line of code is simply “?>”
function curPageURL() {
$pageURL = ‘http’;
if ($_SERVER["HTTPS"] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER["SERVER_PORT"] != “80″) {
$pageURL .= $_SERVER["SERVER_NAME"].”:”.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
Next search for this line of code which should appear directly in the middle of the plugin:
$form .= ‘<div style=”display: none;”>’;
Below this line, paste the following code.
// Addition By: Vince Samios, http://vincesamios.com
$curpageurl = curpageurl();
$visip=$_SERVER['REMOTE_ADDR'];
$form .= ‘<input type=”hidden” name=”page-url” value=”‘ . $curpageurl . ‘” />’;
$form .= ‘<input type=”hidden” name=”visitor-ip” value=”‘ . $visip . ‘” />’;
Now you can reference these values in the email like you would any other form field. Example below
Page: [page-url]
IP: [visitor-ip]
Another useful piece of code by “Travis” is for adding the contact form in PHP - this is useful if you would like to include it in the theme.
echo apply_filters(’the_content’,’
‘);
Update:
Added time and date of submission - Add this in the same place as the Visitor IP and Current Page additions.
date_default_timezone_set(’GMT’);
$timedate = date(’l jS \of F Y h:i:s A’);
$form .= ‘<input type=”hidden” name=”time-date” value=”‘ . $timedate . ‘” />’;
You can reference the time and date in the contact enquiry email by using:
[time-date]
Tags: Contact Form 7, IP Address, Page URL, Theme, Wordpress Plugin
SEO Guide for 2010