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.

can the hooks examples work with multiple forms?

  1. As I read the code snippets for using hooks, like gform_post_submission, can these actually work if you have more than one form? As suggested in another thread I wanted to populate a hidden Post Title and Post Body field, and a hook seems a reasonable way to do it. But if I add another form, it seems it would blow up because of the hook.

    Posted 14 years ago on Monday November 16, 2009 | Permalink
  2. Some hooks pass the Form meta object to the function, and you can add an if statement to run the code for a specific form (i.e. if($form["id"] == 1) .....)

    In your case, you will want to use the gform_post_data filter. That filter also has an equivalent gform_post_data_FORMID that can be used to filter a specific form. The following code seems be what you need.


    add_filter("gform_post_data_2", "set_post_info", 10, 2); //replace 2 with your form id
    function custom_taxonomy($post_data, $form){
    $post_data["post_title"] = $_POST["input_1"]; //replace input_1 with your hidden field name
    $post_data["post_content"] = $_POST["input_2"] //replace input2 with your hidden field name
    return $post_data;
    }

    Posted 14 years ago on Tuesday November 17, 2009 | Permalink
  3. This looks like it may be perfect. I'll let you know.

    Posted 14 years ago on Tuesday November 17, 2009 | Permalink
  4. I can't seem to get it to fire. My form id is one, the form tag named gform_1. I tried the changing the second number to 1 also. I also named the function to match the text in the add_filter call. The version I have is

    add_filter("gform_post_data_1", "set_post_info", 10, 2); //replace 2 with your form id
    function set_post_info($post_data, $form){
    $post_data["post_title"] = $_POST["input_14"]; //replace input_1 with your hidden $field name
    $post_data["post_content"] = $_POST["input_13"]; //replace input2 with your hidden field name
    return $post_data;
    }

    I am just learning all this but it seems like add_filter fires before the user enters data. If so that wouldn't help in my case because I'm trying to get data the user has entered.

    Posted 14 years ago on Tuesday November 17, 2009 | Permalink
  5. Ok. The code you have is correct.
    The problem is that the filter only fires if you have a post field on the form. In your case, you don't. So what we are gonna have to do is add a post title field to the form and hide it with CSS. In the advanced tab, you can set the CSS Class property to "post_title_hidden" and then add the following to your theme's CSS


    .post_title_hidden{display:none}

    Posted 14 years ago on Tuesday November 17, 2009 | Permalink
  6. I do have a post title and post body field on my form. I will hide with that snippet though. I am playin with gform_pre_submission hook with them as I write this.

    How would I get a link to a file uploaded with a file upload field in this form?

    Posted 14 years ago on Tuesday November 17, 2009 | Permalink
  7. panmanphil,
    gform_pre_submission won't help you in this situation.
    To change post data, you want to use gform_post_data or gform_post_submission.
    Do you still have a problem with gform_post_data not firing even though you have the post title field in the form?

    Posted 14 years ago on Tuesday November 17, 2009 | Permalink