Posts

Showing posts with the label contact form 7

Sanitize Form Input in PHP to Prevent SQL Injection and Spam

I had to create a custom form recently for my website in Wordpress and had to ensure I cleaned up the input to prevent SQL injection and SPAM.  I could use the Contact Form 7 plugin but I had to format the input before sending via email. I used the strip_tags() and trim() PHP functions to sanitize the input $name = strip_tags(trim($name)); So if the input in the form field for name was:  <a href="www.scam.com" target="_blank">    WIN</a> The output after using these two functions would just be WIN The trim() function cleared the whitespace before the word "win" and the HTML or PHP tags were removed completely

Add cc email address to Contact Form 7 in Wordpress

Simply add this line under the "Additional Settings" field in your Contact Form 7 settings Cc:you@yourdomain.com

Get Contact Form 7 Posted Data in PHP - Updated for v3.9

Use this function...added to your Wordpress theme's functions.php file This PHP function is run before the form sends an email.  You can use this to store the form data in a database or post to another system. The old $cf7->posted_data['your-email'] doesn't collect the form posted data in the new version of Wordpress Contact Form 7 v3.9+ function something_before_sending_email($cf7) { $submission = WPCF7_Submission::get_instance(); if ( $submission ) { $name = $_POST['your-name']; $email = $_POST['your-email']; } } add_action('wpcf7_before_send_mail',something_before_sending_email'); Thanks to Paulo's post here: http://getlostandwander.blogspot.com/2014/07/contact-form-7-new-way-to-save-data.html

Contact Form 7 Wordpress Plugin Redirect to another page after submission

With the Contact Form 7 plugin in Wordpress this is how I redirected to another page with my Google Conversion Tracking code in place Redirect to unique thank you page with conversion tracking Add this to the "additional settings" section for Contact Form 7: on_sent_ok: "location.replace('http://www.YOURSITEURL.com');"

Contact Form 7 Additional Tags

I found these additional tags for the Contact Form 7 plugin for Wordpress.   I found it helpful when customising my subject line to include the date and time and the post title to Contact Form 7 email to track effective pages with the contact form. [_remote_ip] This tag will be replaced by the sender’s client IP address. [_user_agent] This tag will be replaced by the sender’s user agent information. [_url] This tag will be replaced by the URL of the contact form. [_date] This tag will be replaced by the date of the submission. [_time] This tag will be replaced by the time of the submission. [_post_id] This tag will be replaced by the ID of the post which contains the contact form. [_post_name] This tag will be replaced by the name (slug) of the post which contains the contact form. [_post_title] This tag will be replaced by the title of the post which contains the contact form. [_post_url] This tag will be replaced by the permalink of the post ...