Vince Samios - Internet Entrepreneur

Internet Marketing and Search Engine Optimization Consultant - From the Sky to the Earth and the Ether of the Web
New: Contact Form

Previous Post: Matt Cutts Misses The Point?   Next Post: Dear Google

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’,’

Article Writing

Here is a list of services Niki offers out of the box - you can also ask for something specific in the form below.

Select from the following:

Web Copy - Quality writing for websites

- Quantity


Content rewriting - £3 per 100 words



E-Book Writing - Formatter and PDF'ed



Regular Blog Writing and Posting - 350 Words - One link



Your details:


Name*
Email*
Primary Keywords
Notes:
In order to verify that you are human, you will need to enter
the captcha code below into the corresponding box.
Are you human? captcha

‘);

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: , , , ,

Posted in Internet Marketing 1 year, 5 months ago at 3:30 pm.

8 comments

8 Replies

  1. Thanks for the snippet Vince,

    I was searching your (blog) site for a contact form. I’m looking for an example, but I don’t see any.

  2. admin Apr 3rd 2009

    I’m not using contact form 7 on my blog, just on various money sites. Since posting, I’ve also added a time stamp to contact form 7 so I can see the exact time and date of submission.

  3. darn. i definitely want these features (IP & time stamp) & followed your instructions. but i just couldn’t get this code to work. plug-in would deactivate once the code was inserted. tried it by deactivating the plug-in first & then re-activating it. no dice. kept getting this error message:

    Parse error: syntax error, unexpected T_STRING in /–/–/–/wp-content/plugins/contact-form-7/wp-contact-form-7.php on line 919

    and

    Parse error: syntax error, unexpected ‘:’ in /–/–/–/wp-content/plugins/contact-form-7/wp-contact-form-7.php on line 1810

    any tips on getting it to work would be most appreciated. thanks!

  4. admin Apr 6th 2009

    Hmmm… probably a problem with copy/pasting the code…

    Try pasting the code into notepad, the re-copy pasting it into the plugin. This sometimes helps sanitize the text formatting (but come to think of it, sounds unlikely in this case)

    Also ensure you are pasting it in at the correct spot.

    You don’t need to de-activate the plugin to add the code.

  5. I’m using version 2.2.6 and “$form .= ‘’;” is no where to be found on the code.

  6. You can also add this into the message body part of Contact form 7 and it will send the ip address.

    [wpcf7.remote_ip]

    It’s probably a new feature since this article was written but this article still ranks for the subject in google so it would be good for people to know.

    I got this info from the wordpress site.

  7. This just isn’t working for me. Which .php file in the plugin are we editing here?


Leave a Reply

We may send you emails once in a while, by submitting your comment you consent to receive these emails