How to get Gravity Forms and Zoho CRM to play

Update December 2011

This plugin is now available – see http://helpforwordpress.com/plugins/

Update October 2011!

Since writing this post, I have written a WordPress plugin that does all the heavy lifting to get this to work.

If you use Gravity Forms and Zoho CRM this plugin is for you. It will be released mid November 2011, leave a comment on this post if you would like to be notified when it is available.

–End of update–

This post is going to be pretty specific, but if like me you’ve been looking to get Gravity Forms to send data into Zoho’s CRM tool you’re in the right place.

By themselves these are both great tools that we use all the time. Particularly Gravity Forms, as far as form plugins for WordPress goes, there is no equal.

So here’s the situation.

Zoho CRM has the functionality to create a web to lead form, which is the basic functionality that users generally want to get started. Website visitors can fill in the form and the lead/enquiry ends up in Zoho.

Zoho allows you to create the HTML for such a form but it is really basic. One of the first things you will come against is the ability to mark some fields as required, Zoho’s code doesn’t do it.

So enter Gravity Forms, with all of its customisable goodness!

What you can do is this.

Create the form in Gravity, it can still store the entries in the WordPress database, notify you of the form entry etc.. but then you can also get it to send the data to Zoho.

You need to create a function, I generally use thesis so I put these in custom_functions.php – if you’re using another theme or framework, you’ll have to work out where you store your functions (perhaps functions.php in your template?)

Here is the code, I’ll explain what you need to customise below.

function post_to_crm($entry, $form){

    if($form["id"] != 3) //NOTE: replace 3 with your form id

        return;

?>

	<form method="post" action="http://crm.zoho.com/crm/WebToLeadForm"
name="form_to_crm" id="form_to_crm">
	<input type="hidden" name="First Name" value="<?php echo $entry["1.3"] ?>" />
	<input type="hidden" name="Last Name" value="<?php echo $entry["1.6"] ?>" />
	<input type="hidden" name="Email" value="<?php echo $entry["2"] ?>" />
	<input type="hidden" name="Phone" value="<?php echo $entry["3"] ?>" />
	<input type="hidden" name="LEADCF3" value="<?php echo $entry["4.1"] ?>" />
	<input type="hidden" name="LEADCF2" value="<?php echo $entry["5"] ?>" />

	<input name="xnQsjsdp" type="hidden" value="MHUKz-WiBZI$/" />
	<input name="xmIwtLD" type="hidden" value="5HGdaFP6TlkaxuV8tXZgy2-*B6-MHnNR/" />
	<input name="actionType" type="hidden" value="TGVhZHM=/" />

		</form>
		<script type="text/javascript">
		document.getElementById("form_to_crm").submit();
	</script>
<?php
}

add_action("gform_post_submission", "post_to_crm", 10, 2);

You need to replace the form id at the top of the PHP function with the id of the form, get this from the main Gravity screen where you can view all of your forms and choose one to edit.

The real trick to this is working out what to put in variables like $entry["5"]. The number here corresponds to the ID in the markup for the form when it is rendered. Fields like Name that are broken in two and will be considered field 1 but first will be something like 1.3 and last will be 1.6.

The name attribute in the input tag should simply be the name of the field that Zoho is expecting. A good way to work this out is have a look at the HTML that Zoho creates when making a web to lead form.

Other fields like a text area are more straight forward to work out.

One final tip, I couldn’t get it to work with Gravity’s Ajax enabled so I had to set the redirect of where to land the user when the form was done in the Zoho Web to form settings.

See how you go with all of that, if you have a question feel free to post a comment here and I’ll see if I know the answer!