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 conditional logic to submit button

  1. This request is actually two parts:

    1) Add conditional logic to the submit button, so that it only shows if certain circumstances are met. For instance, I have a form that I want no fields to show up until the select from the first dropdown. Unfortunately, the submit button is still visible and working.

    2) Ability to add additional submit buttons. For instance, in a form with different conditional sections, it could potentially be nice to have a different submit button for each.

    Posted 15 years ago on Wednesday November 18, 2009 | Permalink
  2. Kevin Geary
    Member

    It would be really nice to have the submit button go to a certain follow up page depending on a conditional logic selector.

    For instance...I have an option at the end of my form that says:

    Pay Online
    Pay In Store

    If they choose pay online, submit should take them to pay online page.

    If they choose pay in store, submit should take them to a thank you page with further instructions.

    Posted 15 years ago on Wednesday November 18, 2009 | Permalink
  3. @karateusa

    You can already do something like this with just a few extra steps. You would need to pass a parameter from the form to your confirmation page and then process a redirect based on the value in the string.

    screenshot

    Then, on the confirmation page, you could use a simple switch statement to send the visitor to the page of your choice.

    <?php
    $purchase = $_GET['purchase'];
    
    switch ($purchase)
    {
    
    case online:
    header("Location: http://www.domain.com/online.html");
    break;
    
    case in_store:
    header("Location: http://www.domain.com/in-store.html");
    break;
    
    }
    ?>

    of course, these are my samples, you would need to adjust the field names and values to suit your form.

    Posted 15 years ago on Wednesday November 18, 2009 | Permalink
  4. funkytown
    Member

    Having conditional logic for the submit button would be very helpful for me as well. I'd like to create a little padlock game with a series of multiple choice conditions. When the correct pattern is entered, the user would be able to submit the form and enter to win a prize. Anyone have any thoughts on this?

    Posted 15 years ago on Wednesday November 25, 2009 | Permalink
  5. So, can you add additional submit buttons?

    Posted 14 years ago on Sunday January 3, 2010 | Permalink
  6. @kyounger No you can't currently have additional submit buttons. These are feature requests.

    Posted 14 years ago on Sunday January 3, 2010 | Permalink
  7. knife
    Member

    Yeah definitely think there should be an easier way to add a T's and C's section. It's pretty common to have the submit button of a form inactive until a T's and C's checkbox has been clicked.

    Posted 13 years ago on Tuesday January 25, 2011 | Permalink
  8. @knife - conditional logic can be applied to the submit button now. You can set a single checkbox for "agree to terms of service" and base the conditional logic on it. If the field isn't checked, the submit button doesn't show.

    The button conditional logic options can be found under the main form settings for each form.

    Posted 13 years ago on Tuesday January 25, 2011 | Permalink
  9. danielpettifer
    Member

    Kevin in your steps above....where should i insert the php code?

    i am working on an educational site where people need to choose courses, the submit button needs to redirect to different event registration pages...

    thanks in advance :)

    Posted 12 years ago on Friday January 20, 2012 | Permalink
  10. danielpettifer
    Member

    Also, how could i change this for different forms, there will be a total of six forms that will need redirecting....

    Posted 12 years ago on Friday January 20, 2012 | Permalink
  11. @danielpettifer, regarding this code:
    http://www.gravityhelp.com/forums/topic/add-conditional-logic-to-submit-button#post-1591

    That is a discrete PHP file stored on your server. Call it whatever you want (redirection.php is OK) and put it in your theme folder. Then use that file as part of the redirect URL. So the url will look like

    http://example.com/wp-content/themes/themename/redirection.php

    Now, that file has the logic to "catch" the value of "purchase" you are sending.

    What I would do is send one parameter name (in this case 'purchase') and send different values. Then the code (the "case" statements) will be extended to handle all your options (6 you say.) So, maybe you will have a parameter name of "course" and send it in the query string like this:

    ?course=algebra
    ?course=spelling
    ?course=cooking
    ?course=bicycling
    ?course=kayaking
    ?course=sleeping

    If that were the case, you will use change "purchase" to "course" and instead of 2 cases in the switch statement, you will have 6, and each one is exactly as listed above.

    Please let us know if you need more help. This is a very old topic and our advice has changed and gotten better since this was written. I can't find the newer topic though.

    Posted 12 years ago on Monday January 30, 2012 | Permalink
  12. danielpettifer
    Member

    Thanks for your help....have been busy sorry :)

    It's becoming slightly more complicated....I will explain

    I have a central webpage that gives you the ability to book a course in one of our seven branches... I want to put the gravity form in a sidebar widget and I would them to be able to choose between two different parameters... the branch location...and the course...... I think it will be something along the lines of if parameter1=london and parameter2=cooking then redirect to http://blablabla.....

    But I really have no idea how to implement this.....I can follow a tutorial if you have any advice on where to look.....

    thanks again for your amazing service!

    Posted 12 years ago on Saturday February 18, 2012 | Permalink
  13. danielpettifer
    Member

    I'm also building this on a local server at the moment......the redirect doesn't seem to be working...will it fail if it's not on a live site..?

    Posted 12 years ago on Saturday February 18, 2012 | Permalink
  14. danielpettifer
    Member

    OK.......so call me stupid but............in the confirmation tab I can "Pass Field Data Via Query String".

    I can separate the field data with a / = for example : {Branch:1}/{Course:2}

    This works perfectly, however........ it is putting a question mark before {Branch:1}

    http:www.mycourse.com/?london/cooking

    Could i possibly clean up this information as it is passed...this would be much simpler

    Posted 12 years ago on Saturday February 18, 2012 | Permalink
  15. danielpettifer
    Member

    Please can you help with this..... .. . . . I have everything set up but I am using a local server (mamp),
    it's set to port 8888 and is being automatically shortened to localhost which isn't working. Do you think I am experiencing problems because I am working locally? I tried hosting the redirection file on another server but that also doesn't work.......

    Posted 12 years ago on Monday February 20, 2012 | Permalink