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.

Conditional Redirect with sidebar form while keeping field data

  1. Hi,
    I've been trying to get a teaser form to redirect to different forms based on selection while retaining field data. I've been using these two forum posts as guides:

    http://www.gravityhelp.com/forums/topic/terms-of-conditions#post-7442
    and
    http://www.gravityhelp.com/forums/topic/conditional-redirects-preserving-posted-data

    I was able to get it to redirect properly, but can't seem to work out keeping the field data. Here's the scenario:

    A teaser form has two fields. A radio button for Buy/Sell/BuyandSell and a drop down list of the state they are looking for. The radio button selection directs you to what form you will fill out and I want to retain the State in the new form you are sent to. The redirect code looks like

    $agree == $_GET['BuySell'];
    switch ($agree)
    	    {
    
    	        case "Buy a Home":
    	        // if buy redirect to the following page
    	        header("Location: WEBSITE_URL_1");
    	        break;
    
    	        case "Sell a Home":
    	        // if sell redirect to the following page
    	        header("Location: WEBSITE_URL_2");
    	        break;
    
    			case "BuySellHome":
    	        // if buy and sell redirect to the following page
    	        header("Location: WEBSITE_URL_3");
    	        break;        
    
    	    }

    but couldn't incorporate either of the methods from the second post successfully. Any help at all would be greatly appreciated. Thanks!

    Posted 11 years ago on Saturday December 1, 2012 | Permalink
  2. Instead of WEBSITE_URL_1, 2 and 3, those URLs will have to have query strings which contain the parameter name of the value you want to preserve.

    Maybe your URLs look like this in reality:

    http://example.com/buy-a-home/
    http://example.com/sell-a-home/
    http://example.com/buy-sell-home/

    That is fine, but I am assuming you want to save maybe name and email address. In the teaser form if your first field was a name field, and your second field was an email address, those URLs would look something like this:
    http://example.com/buy-a-home/?fname=$lead['1.3']&lname=$lead['1.6']&email=$lead['2']
    http://example.com/sell-a-home/?fname=$lead['1.3']&lname=$lead['1.6']&email=$lead['2']
    http://example.com/buy-sell-home/?fname=$lead['1.3']&lname=$lead['1.6']&email=$lead['2']

    Your second form, the form on all three of these pages, will have to have "Allow field to be populated dynamically" checked, and the parameter names will need to match these here:

    fname
    lname
    email

    Let us know if you need more help.

    Posted 11 years ago on Saturday December 1, 2012 | Permalink
  3. Thank you for the quick response! I still seem to be having an issue though. I'm receiving this error when I submit the form:

    Parse error: syntax error, unexpected T_LNUMBER in /home/tmueller/public_html/rebateagents.net/wp-content/themes/theme1411/page-formsplash.php on line 10

    Just to see the whole block, here's lines 8-11

    case "Buy a Home":
    	        // if buy redirect to the following page
    	        header('Location: http://www.rebateagents.net/buy-form/?State=$lead'2'');
    	        break;

    ?State is the parameter name of the field I want to preserve and $lead['2'] is it's ID, correct?

    Also, if it's any help Dreamweaver code syntax flagged the single quotes surrounding 2 as an issue. Just to restate my goals, one field (Buy/Sell/Buy and Sell) is dictating which redirect to use and the only information I want carried over to the next form is which State they select in a drop down. Thanks again!

    Posted 11 years ago on Monday December 3, 2012 | Permalink
  4. Whoa, don't know what I did to cause it, but line 3 of the code I just submitted certainly isn't supposed to look like that. It's

    case "Buy a Home":
    // if buy redirect to the following page
    header('Location: http://www.rebateagents.net/buy-form/?State=$lead'2']');
    break;

    Posted 11 years ago on Monday December 3, 2012 | Permalink
  5. The syntax highlighter or forum software here will auto link hyperlinks and add the rel='nofollow' as well. Can you post your code at pastebin.com or pastie.org so we can see it unaltered? Just paste the link here so we can see exactly what you are using.

    Posted 11 years ago on Monday December 3, 2012 | Permalink
  6. Sure, it can be seen here:

    http://pastebin.com/NfzhRueh

    Note: only the top case has been changed to (try to)work with the query string.

    Thanks again!

    Posted 11 years ago on Tuesday December 4, 2012 | Permalink
  7. Can you post all of your code, including the hook or filter you're using, and the complete function? We need to see it in its entirety to know why it's not working, especially since you have a syntax error.

    One problem with this specific bit of code though is that you cannot use single quotes twice on line 3 (and any subsequent URLs you're going to build like that.) And variables will not be parsed by PHP inside single quotes. Try these two lines instead of line 3:

    http://pastebin.com/3uq3DdVk

    Or, you can build the URL before the case statement if that will work for you.

    Posted 11 years ago on Thursday December 6, 2012 | Permalink
  8. Sorry about that. All the code in the php doc is shown here:

    http://pastebin.com/exxUTkph

    If there is supposed to be supplemental code in other files then I don't have them.

    I still get a syntax error with the alternate lines you gave me. As I'm sure is apparent by now, I'm not well versed in php - so I apologize for not being able to do what are probably simple alterations in syntax to you.

    Posted 11 years ago on Thursday December 6, 2012 | Permalink