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.

Linking Forms Conditionally

  1. Is there a way to generate a 'Submit' button at the end of a form that will link users to another form based on choices they made in the form? For example, if you have 2 questions, is there a way to generate a unique 'Submit' button if the user answers a certain way in Question 1 and Questions 2, but another 'Submit' button if a user answers those same questions differently?

    I am interested in finding a way to dynamically link one form to another, based on conditional statements that will guide the user to different forms based on their questions on the current form. I figure the only way to do this is by generating a button that is unique to set of variables and add code for that button to link to a specific page (with the corresponding form on it). I appreciate any help. Thanks!

    Posted 12 years ago on Monday April 16, 2012 | Permalink
  2. kyle
    Member

    When I've had to do this, I just setup a redirect template... so something like:

    http://mysite.com/redirect

    and set my form to go there on submit (and pass all (or the ones you need to check) the values in the query string. The landing url ends up looking like this:

    http://mysite.com/redirect/?q1=Felix&q2=Oscar

    Then I create a template-redirect.php file, and use it for the redirect page. That page template looks like:

    <?php
    /*
    Template Name: Form Redirect
    */
    
    $q1 = $_GET['q1'] ; // where q1 is what you passed in the query string
    $q2 = $_GET['q2'] ;
    
    // I use else, but depending on your data you could use a switch or whathaveyou.
    
    if ($q1 == 'Felix' && $q2 == 'Oscar')
      wp_redirect('http://mysite.com/form1a');
    else
      wp_redirect('http://mysite.com/form1b');
    
    ?>
    Posted 12 years ago on Monday April 16, 2012 | Permalink
  3. Thanks for posting your solution Kyle.

    Posted 12 years ago on Monday April 16, 2012 | Permalink
  4. Thanks Kyle. I will try this in the morning!

    Posted 12 years ago on Tuesday April 17, 2012 | Permalink
  5. Just a quick follow up to this issue- I tried Kyle's suggestion (thanks again!), but it was not accomplishing what I was hoping it would or I was doing it wrong.

    As an alternative to Kyle's method, I was thinking of coding several 'Submit' buttons on a form and using Conditional Logic to determine when a specific button would appear. I read on http://www.gravityhelp.com/forums/topic/using-a that the submit button is <button type="submit">. Would I be able to use a HTML block, use input for the submit button and at the same time insert code to link to the appropriate form? Pretty much just remove the default 'Submit' button, and replace it with a custom one that would submit the form (as the submit button currently does) and link to the next form (based on Conditional Logic).

    What I am dealing with is about 18 forms, each of which the user needs to answer questions. These questions have several choices, and each choice helps 'define' the need of the user. Each question has several choices and based on how the user is 'defined' will alter which of the forms that user will be directed to next. The tricky part that I am working through, is that a few of the forms have several of these 'defining' questions, so the workflow is pretty tricky.

    If I could use the HTML block to create my own 'Submit' buttons, and determine when a particular 'Submit' button appears I feel I would be able to accomplish this project. Even if this fix is short-term that would be fine, as the client needs to update their system before I can do a more elegant fix (like Kyle's suggestion, etc.). Thanks!

    Posted 12 years ago on Wednesday April 18, 2012 | Permalink
  6. OH SNAP SON! I finally got it! Wow... I was applying the custom template Kyle suggest to the wrong page ><. Dude, thank you so much- figuring out the workflow of the client's complicated forms was giving me a headache... getting this to work just brightened my day. Thank you so much!

    Posted 12 years ago on Wednesday April 18, 2012 | Permalink
  7. David Peralty

    Glad to hear it all worked out. Loved the intro to your last response.

    Posted 12 years ago on Wednesday April 18, 2012 | Permalink

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