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.

1.5RC4: $form['id']) not available?

  1. STB
    Member

    I got some custom code working allright with a filter,
    but now I only want it to work on form number 1.

    So I added this to the theme's functions.php:

    add_action("gform_pre_submission_filter", "update_autoresponder");
    
    if($form['id'] != 1) return $form; //only use on form1 else return
    
    function update_autoresponder($form) {
    
    do something
    }
    
    // return the modified form
    return $form;
    }

    The code should thus only run on form1, but instead it is also run on form2, form3 etc.

    Next, for debug purposes, I changed the code to the following for debug purposes:

    add_action("gform_pre_submission_filter", "update_autoresponder");
    
    if($form['id'] != 1) return $form; //only use on form1 else return
    
    function update_autoresponder($form) {
    
    return $form; // <-- added new line, to stop processing rest of the code regardless of $form['id']
    
    do something
    }
    
    // return the modified form
    return $form;
    }

    This did indeed result in the added custom code to be skipped.

    Next I tried switching back from 1.5RC4 to 1.4,
    and I used the orignial code, as posted above here.
    And things worked as expexted as well, only performing the custom code for form 1.

    I cant figure out what is wrong here... but Im beginning to think that the $form object, or the $form['id'] array is not globally available in 1.5RC4.

    Any help would be much appreciated.
    Site URL + admin login available on request per email (mailaddress filled out in my profile)

    Posted 13 years ago on Thursday February 17, 2011 | Permalink
  2. First the filter you are trying to use is called gform_pre_submission, not gform_pre_submission_filter.

    Second, the code you have in place is going to execute for all forms because you aren't applying it to a specific form id. If you it to run just for one form id, you need to change your code.

    Change this:

    add_action("gform_pre_submission_filter", "update_autoresponder");

    To this:

    add_action("gform_pre_submission_ID", "update_autoresponder");

    Replace the ID appended to the end of gform_pre_submission with the ID of the form you want to customize.

    You would either use gform_pre_submission to apply the change to all forms, or gform_pre_submission_ID with the id of your form to apply it to a specific form.

    Posted 13 years ago on Thursday February 17, 2011 | Permalink
  3. STB
    Member

    Awesome. Thanks for the super fast reply and explanation Carl!
    That did the trick, it's working now.

    I will keep spreading the word about your great plugin + excellent service.

    Posted 13 years ago on Thursday February 17, 2011 | Permalink
  4. STB
    Member

    Update:

    I posted a bit too early above.

    After some fiddling around some more , this is what worked for me in the end.
    add_action("gform_pre_submission_filter_1", "update_autoresponder");

    This lets me change the autoresponder fields for form1 while not altering them on form2, form3 etc.

    So, the filter I need *is* called gform_pre_submission_filter_ID, not gform_pre_submission_ID
    (See also this codesnippet from David Smith http://www.gravityhelp.com/forums/topic/tell-a-friend-form-query)

    Posted 13 years ago on Thursday February 17, 2011 | Permalink
  5. @STB Yes, I misread your initial post. There are actually 2 different hooks in Gravity Forms that have similar names:

    gform_pre_submission
    Use this hook to perform actions after form validation, but before sending notifications and storing the entry data.

    gform_pre_submission_filter
    Use this hook to manipulate the Form Object before sending notifications and storing entry data.

    Glad you got it working and I could point you in the right direction, at least with the _ID piece of the puzzle :)

    Posted 13 years ago on Thursday February 17, 2011 | Permalink