Blog

Sharing WordPress tips and tricks as I find them

Connecting your Contact Form to CRM

It took a bit of work, but a few months ago I finally figured out a way to connect my contact form to my CRM. Here’s the tools you’ll need:

Build the form

Using Gravity Forms, create a contact form with all the relevant fields you want to collect. Out of the box, GF let’s you create simple posts using your form. Using the GF + CPT plugin, you’ll be able to link the fields to meta and taxonomy fields. Here’s the fields I’m using in my form:

  • Your Name = Post Title. This field also has all the extra post data on it. I’m publishing it as a Draft post (I publish it once I’ve responded) in the “Prospect” category.
  • Your Email = Post Meta field for email (_crm_client_email).
  • Your Phone = Post Meta field for phone (_crm_client_phone)
  • URL = Post Meta field for url (_crm_client_url)
  • How did you find me = dropdown populated by the Source taxonomy
  • Message = Post Body
  • [Hidden] Sales Status = Post Meta for ( _crm_sales_status) setting it to Inquiry
  • [Hidden] Inquiry Date = Post Meta for ( _crm_date_inquiry ) setting it to current date

I wasn’t able to have a hidden field that sets the value of a taxonomy, so I added this to my functions.php file in TwentyTen CRM to set a default value. If you don’t specify a value for the Point of Contact taxonomy, it sets it to “Email Form” when you publish the post (thanks Michael Fields).

Create Contact Page in CRM

Once you’ve created your form, it’s time to create a contact page. Go to Pages > Add New, create a page called Contact, then add the appropriate shortcode to it to add the form.

But we want the contact page on our website, not on our CRM. Let’s strip this page bare so we can embed it to your actual site as an iFrame.

I created a very simple page template in a file called template-form.php (for TwentyTen CRM) and template-new-form.php (for Genesis CRM) which strips out the elements I don’t want.

Make the Contact Page Accessible

So now we have a functioning (and bare) contact form page that looks something like this. If you’d like, add some CSS to style it to match your actual site, like this.

But because we have the Registered Users Only plugin, only logged in users can access the form. Luckily the plugin provides us a filter to specify certain pages that are open to everyone.

Use this code in your functions.php file to make the form page accessible. Change ‘form’ to whatever the page slug of your contact page is (mine is ‘form’).

Finally, Add the Contact Form to Website

On your public website, create a contact page and embed the CRM contact form as an iFrame. Here’s what my embed code looks like.

Now you’ll have a contact form that will auto-populate your CRM with the contact’s information. They’ll show up as Drafts, and you can click “Publish” once you’ve responded. This was hugely helpful for me on my recent trip.

10 Comments

  1. I had problems with the form exclusion.
    to fix I changed registered-users-only.php line 62

    if ( in_array( basename($_SERVER['REQUEST_URI']), apply_filters( ‘registered-users-only_exclusions’, $this->exclusions) ) ) return;

    it was checking PHP_SELF which fails with permalinks (it might even fail with standard ?p=IDNUM as PHP_SELF will always match index.php.
    REQUEST_URI can check any variable in the URI :)

  2. Thanks, though I found the contact page performed odd so I modified the page template like so:

    /**
    * Template Name: Contact
    *
    * A custom page template for the contact page.
    *
    * @package CRM
    * @subpackage Template
    */
    global $prefix;

    remove_action('wp_head', 'rel_canonical');
    remove_action('wp_head', 'wp_generator');

    wp_head();

    gravity_form( 1, false, false, false, '', false );

    print_footer_scripts();

  3. Hey Bill,
    I’m attempting to get this working and I can actually get the form working easily. So that’s good. I’m having a hard time with the code you put into your functions.php file.
    Here’s the error I get when putting into the genesis-crm functions.php file:

    Fatal error: Cannot redeclare mfields_set_default_object_terms() (previously declared in /home/yannibmb/public_html/crm/wp-content/themes/billerickson-Genesis-CRM-a9f2c43/functions.php:190) in /home/yannibmb/public_html/crm/wp-content/themes/billerickson-Genesis-CRM-a9f2c43/functions.php on line 426

    Seems to me that it’s saying I’m trying to do this more than once, but i’m not seeing where or how. Can you point me in the right direction, sir?

    Thank you as always.

    • Bill Erickson says:

      It’s saying you are delaring the function mfields_set_default_object_terms() both on line 190 and line 426 of your functions.php file.

  4. Hi Bill,

    appreciate this is a bit of an old thread but I’ve been playing with the CRM theme and love it. So much so that I’m implementing it on my site and want to use it in my workflow.

    I have the CRM setup as a separate site as per your instructions and have followed everything through and tested. The only thing that’s not working is being able to exclude the form page from the Registered Only plugin.

    My slug for the form page is “form” just like yours, but if I go to that URL (http://crm.24reach.com/form) I just get redirected to the login form. I haven’t modified that section of functions.php so it should work, but doesn’t.

    Everything else has gone to plan except this. Any chance of a steer?

    • Bill Erickson says:

      Are you sure that filter is running? Make sure this is in your functions.php file: add_filter(‘registered-users-only_exclusions’, ‘crm_form_exclusion’);

      Other than that, I’d dive into the code of Registered Users Only to see why that’s not registering. It’s comparing what you provide to basename($_SERVER['PHP_SELF']) . Maybe add a test function like this to functions.php, then visit your contact page while logged in. That should display the page’s basename at the top of the page. Make sure what you’re passing to the filter matches that exactly.

      • Yes. The filter is running. I have that line towards the top of the functions.php file.

        When including the test function, the contact form page displays ‘index.php’ as the basename. Is that right?

        Thanks for your support with this.

        • OK – now I have it working. I used my namesake’s alteration to the actual plugin above as follows:

          “I had problems with the form exclusion.
          to fix I changed registered-users-only.php line 62
          if ( in_array( basename($_SERVER['REQUEST_URI']), apply_filters( ‘registered-users-only_exclusions’, $this->exclusions) ) ) return;
          it was checking PHP_SELF which fails with permalinks (it might even fail with standard ?p=IDNUM as PHP_SELF will always match index.php.
          REQUEST_URI can check any variable in the URI ”

          All working fine – thanks for your help, Bill.

          • Just as a side note, I was able to get Private Only to work instead of Registered Users Only without any modifcation. It has the option to have one public page, which I set to my contact form, and also disables the feed, though that’s less of a concern.

  5. Hello,
    I feel a bit stupid now…. Despite being fully happy with the free contact forms availalble, I bought the “Gravity Forms” plugin since I wanted to follow the instructions in this article and (hopefully) get a useful and slim CRM.

    However, it doesn’t work.
    Or rather: “Your Name = Post Title…” and “Message = Post Body” functions as described, but not “Source taxonomy” or any of the Post Meta fields.
    And I don’t know if it is the “Gravity Forms” plugin that is broken, or if it is the “Gravity Forms + Custom Post Types” plugin, or Thomas Griffin’s “CRM Press” theme. I just know that I wasted 40 bucks on something that doesn’t work, with seemingly no way to get refunded.

    That’s life I guess. I shouldn’t complain. I just wanted to post this to warn others from wasting money on this non-functional “Gravity Forms” plugin.

Join the Conversation

If you'd like to include code in your post, please post it to http://gist.github.com and include a link.