PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Add option to only run action when selected

  1. I'm having a difficult time trying to figure out where/how best to do this. I'm looking for a way that I can build a form, add a checkbox to the "advanced" tab (perhaps the best way?!?) that will allow me to look for an option so that I can run an action if this option is selected.

    The non-tech version of this is that I want to allow a user to select an option to send the form to HubSpot. I've got everything on the backend working, but the reality is that we have forms that aren't necessarily needing to be sent to HubSpot, so I'm trying to find a way that would make the best sense.

    I know there's an older plugin out there that already does this, but it's not using the new API. So I've been working on one. :) I'll release open-source if I can get this working the way I expect it to.

    If you have an easy example, that would be awesome! Thanks!!

    Posted 11 years ago on Monday January 28, 2013 | Permalink
  2. When you say "everything working on the back end" do you mean that everything is being sent fine to HubSpot right now? The issue is, you want to give form builders the option to check a box and NOT have the submission go to HubSpot?

    It sounds like new forms are being created all the time, so using form IDs in your filter or action calls is probably not practical?

    How about using the gform_advanced_settings filter: http://www.gravityhelp.com/documentation/page/Gform_advanced_settings

    Posted 11 years ago on Tuesday January 29, 2013 | Permalink
  3. Hey Chris, thanks for the reply! Short answer is yes. I want to be able to select which forms pass through the plugin, so having that be an option I can allow the user to select on a per form basis is what I'm looking for. What I'm going to do is reverse your thought. I'm going to set it up that if you want the form/entries to go to HubSpot, you'll need to click the check box. Either way, you just pointed me in the right direction! Thanks!! I'm sure I might have another question after I get this part working.

    Posted 11 years ago on Tuesday January 29, 2013 | Permalink
  4. OK, let us know if you need any more help.

    Posted 11 years ago on Wednesday January 30, 2013 | Permalink
  5. Alright Chris, might just need a little bit more help getting this to work right. Here's what I've got to show the checkbox, https://gist.github.com/4676079. This works, but when I click it (so it's checked), save the form and come back to it, it's not showing that I selected the option. So I'm not sure how GF is saving that setting.

    Posted 11 years ago on Wednesday January 30, 2013 | Permalink
  6. Also, once I get it to do that, how to I check to see if that option is selected? Will it show up in the $form object? If so, I can check to see its in there and see if it's set to true/false?

    Posted 11 years ago on Wednesday January 30, 2013 | Permalink
  7. You are very close. You need to change two things.
    1- Change the SetFieldProperty() function call to:

    form['sendHubSpot'] = this.checked;

    SetFieldProperty() is used for field properties and you need to set your property to the form object

    2- When loading your checkbox with the value, use the gform_load_form_settings instead of gform_load_field_settings. Following is an example:

    jQuery(document).bind("gform_load_form_settings", function(event, field, form){
    jQuery("#field_hubspot_setting").attr("checked", form["sendHubSpot"] == true);
    });

    Then, yea, your property will be loaded in the $form object. So $form['sendHubSpot'] is the way to access it from the hooks.
    I hope this helps.

    Posted 11 years ago on Thursday January 31, 2013 | Permalink