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.

Gform submit button Filter

  1. Hello,

    I have been able to change my GF submit button using 'add_filter("gform_submit_button", "form_submit_button", 10, 2); '

    However it changes the submit button for all of my forms on the site, how would I go about only changing the submit button based on the forms id?

    Posted 12 years ago on Wednesday January 4, 2012 | Permalink
  2. You would pass the form ID like this:

    // filter the Gravity Forms button type on Form ID 1
    add_filter("gform_submit_button_1", "form_submit_button", 10, 2);
    function form_submit_button($button, $form){
        return "<button class='button' id='gform_submit_button_{$form["id"]}'><span>Submit</span></button>";
    }

    You can see the gform_submit_button_1 is the change.

    Posted 12 years ago on Wednesday January 4, 2012 | Permalink
  3. Ahh yes that works.

    Is it possible to pass an array of form ID's? so if I wanted to change the submit button on lets say 3 different forms.

    I could obviously just run the same code 3 different times with different IDS, but perhaps there is a simpler way.

    Posted 12 years ago on Wednesday January 4, 2012 | Permalink
  4. Instead of this:

    [php]
    gform_submit_button_1

    use this:

    [php]
    gform_submit_button

    And then in the code below do this:

    [php]
    if($form['id'] == 1 || $form['id'] == 7 || $form['id'] == 5) {
    // then return the custom button for forms 1, 5 or 7

    You can use whatever PHP conditional you are comfortable with (I used simple OR logic). You could put the form IDs into an array and then check the array for the existence of the ID.

    It might look like this when you are done:

    [php]
    // filter the Gravity Forms button type on Form ID 1
    add_filter("gform_submit_button", "form_submit_button", 10, 2);
    function form_submit_button($button, $form) {
        if ($form['id'] == 1 || $form['id'] == 7 || $form['id'] == 5) {
            return "<button class='button' id='gform_submit_button_{$form["id"]}'><span>Submit</span></button>";
        }
    }
    Posted 12 years ago on Wednesday January 4, 2012 | Permalink
  5. Thats perfect! Thanks so much for the amazing help!

    Posted 12 years ago on Thursday January 5, 2012 | Permalink
  6. Glad you got that working. Thanks for the update.

    Posted 12 years ago on Friday January 6, 2012 | Permalink

This topic has been resolved and has been closed to new replies.