Showing posts with label wordpress. Show all posts
Showing posts with label wordpress. Show all posts

Friday, August 12, 2016

3rd party integration for contact form 7 API style

I was requested to fix the issue permanently because every contact form 7 update would cause erasing of the custom code and I need to fix it everytime. Not good. So I did a quick search and found the plugin: forms-3rdparty-integration.

Once installed, the basic setup is binding your fields;
1. Input the fields you need to send to your application under "3rd party service: service 1"
2. Add your custom URL (try to include something very unique - I use a ?key=<randomkey>)
3. On your application, using the <randomkey> you can take in the values using $_POST

Done.

Let me know if you would like any expansion or anything is unclear, etc in the comments below.
Thank you

Friday, October 17, 2014

Contact form 7 telephone number digits restriction modification

If you use the contact form 7 plugin (version 4.0) for contact information gathering on your wordpress site and want to restrict the minimum and maximum digits a user enters but without sacrificing the brackets, spaces or plus sign here's how I found out to do this.

In the file: formatting.php line 153 (found under /your/host/wordpressdir/wp-content/plugins/contact-form-7/includes )
comment out the original line like so (in case you want to revert the changes):
//$result = preg_match( '/^[+]?[0-9() -]*$/', $tel );

and add the following:
$pattrn = array( " ", "\r", "\n", "-", ".", "(", ")", "_", "'", "`", "+");
$newphone = str_replace( $pattrn , '' , $tel );
if( strlen( $newphone ) == 10 && preg_match( '/^[0-9]*$/', $newphone )) $result = true;
else $result = false;

Now the user must enter 10 digits no matter if the formatting is +(123) 123 - 1231 with or without spacing and brackets and even underscore or plus sign.

In case anyone is wondering why this is required is because sometimes users might omit their area code (the first three digits) and it becomes very hard to guess what it might be to dial it.

I'm sure this part can be improved because the digits are hard coded and there might be other countries that require more or less so if this was setup from admin and input it there but I don't know how to do this yet and don't require so if someone wants to improve or any feedback let me know in the comments below.

Also check out my previous article if you need to send the data to a database of your own here.

Thanks for visiting.

Saturday, April 7, 2012

Contact Form 7 send contact to database

UPDATE: Aug, 2016 -  There's a better solution using an add-on plugin for wordpress.



For archive purpose:

I noticed since Sept 23, 2014 (but maybe the change was made earlier since we didn't update the plugin until now) There are structure and code changes made in the new version which means this will not work. If you don't see the classes.php file you know you have the newer version (4.0 for me). New solution: modify the contact-form.php file around line 560 after:
if ( $submission->is( 'mail_sent' ) ) {
if ( $this->in_demo_mode() ) {
$result['status'] = 'demo_mode';
}
add:
require_once (getcwd().'/wsdl/func.php');
webRequest2($submission->get_posted_data());

on your own code you might need to add [0] at the end of the array fetching for each field.


Otherwise if you have an older version read the original solution:

If you use the quick form creation on wordpress with the popular Contact Form 7 while sending the data (not only to email) to a database of your CRM or related software to help manage the leads, this should help.

Although I am aware of the database extension I couldn't spend time to figure it out because we already had a database solution from a custom site that didn't use wordpress prior, so it was very simple once I found where the data is being sent:

Found the location in our install to be under /your-domain/wordpress/wp-content/plugins/contact-form-7/includes/classes.php

In this file you edit the part which is around line 278 in the submit function under the code
} elseif ( $this->mail() ) {

add your code, in my case it's two lines:
$cid=webRequest2($this->setup_posted_data());
sendAnalytics($cid);

I covered more on the analytics software here.

As simple as this you have the data and can send it to your database (which could and probably should be on different host).

Let me know what you think!