Post Perch form to a CRM?

  • Hi,

    I need to post a Perch form to a CRM. Not sure how to approach it, as I've never done this before...

    If it was a standard contact form, I'd most likely generate the form in the CRM and use any form code provided.

    This is my current setup. I'm using one Perch form on multiple project pages, depending on where the form is submitted I pass in the project name as a hidden field which then populates the subject field. This approach works really well when everything is done in Perch.

    Can I use Perch forms to collect the form data, including the project name in a hidden field and then pass that on to the CRM?


  • Hi Stephen,

    Like JordinB suggested you can build an app with a form handler and use it to handle these forms. Your app's form handler can also pass on the response to the Perch Forms app if you want to use it to store a copy of the response in the database.

    Alternatively, you can build an app that listens to the perch_forms.received event. This approach is useful if you rely on the Forms app for handling spam. See: Multiple apps in the form tag and SPAM!

  • Hey, thanks for the replies.

    1. I'm trying to get my head around this, as I've not done this before.
    2. I actually have multiple forms throughout website, will I need an app per form?
    3. I want to use perch_forms to handle validation, redirects and spam.
    4. All I want the form handler to do it pass on the data to the CRM
    5. I'd then add the app ID sm_contact to the form tag <perch:form id="contact" app="perch_forms sm_contact" role="form" method="post" >, correct?
    6. I found the code below on this website
    1. I appreciate the code above isn't what I'd use, but I think it gives me an idea of what I'm trying to achieve.
    2. So, the form handler is used to grab the IDs from the perch:form and converts them into variables, that can be used by a CRM?
    3. How do I get the data in the form handler into the CRM?
      1. Would there be something like an action attribute within the app, this would forward the data to the CRM?
  • You would add your form handler to addons/apps/sm_contact/runtime.php:

    1. function sm_contact_form_handler($SubmittedForm) {
    2. if($SubmittedForm->validate()) {
    3. // access the data via $SubmittedForm->data instead of $_POST
    4. }
    5. }

    The validate() method will throw the basic errors for you (e.g. required/email fields). You can also programmatically throw an error:

    1. $SubmittedForm->throw_error('error_type', 'field_id');
    2. $SubmittedForm->throw_error('max_upload_size', 'cv');

    And you can pass the response to another app (e.g. the perch_forms app):

    1. $SubmittedForm->redispatch('perch_forms');