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.

Best method for passing variables

  1. Forgive this non-coder's question. I can cut and paste into functions.php with the best of them, but understand little of the mechanics.

    I've created an order form that accepts a pre-defined discount code. If the code is correct, a higher price field is hidden and a lower price field becomes visible. I have figured out how to pass 2 variables to the form using a query string at the end of a URL. I intend to publish the URL + query string to select email list subscribers. Everything works, but of course if the recipient navigates to any other page of the website, the variables are lost. And when they navigate back to the form, the form conditions revert to a standard state, and the higher price.

    Is there a relatively easy way to maintain the passed parameters for a session? Ideally, I'd like to allow users who navigate to the site using the URL + query string to move around the site and return to the form with the discount code still intact. A cookie? And if so, I'll need a step-by-step.

    Posted 11 years ago on Tuesday February 19, 2013 | Permalink
  2. David Peralty

    You would want to use a cookie or session variables, and it would go above and beyond our support to do walk throughs on these topics. If you search for PHP writing cookie or PHP sessions on Google, you'll find a great deal of tutorials relating to this.

    Posted 11 years ago on Tuesday February 19, 2013 | Permalink
  3. David. I completely understand the necessary limits of support through this forum. Your answer at least gives me the confidence to pursue this inquiry via search. Thanks!

    Posted 11 years ago on Tuesday February 19, 2013 | Permalink
  4. David Peralty

    Yeah, it is definitely possible, and you should be able to do it without too much issue. Just search the stuff out on Google, and I am sure you'll find a tutorial that helps you with what you need.

    Posted 11 years ago on Tuesday February 19, 2013 | Permalink
  5. Perhaps this question will be within the limits of support?

    I've figured out how to implement session variables in my Wordpress installation and pass 2 bits of data embedded in a query string to the variables. I've set two fields in my form so they may be populated dynamically.

    Now I just need the syntax that will allow the form to access those session variables when the form is called. I'm using:

    add_filter("gform_field_value_discount_code", "populate_discount_code");
    function populate_have_code($value){
    return $_SESSION['discount_code_s'];
    }

    But this is throwing an error.

    Posted 11 years ago on Wednesday February 20, 2013 | Permalink
  6. Never mind ... typo on line 3. You can close this.

    Posted 11 years ago on Wednesday February 20, 2013 | Permalink
  7. Ah yes, you called a non-existent function in the filter. This is more correct:

    [php]
    add_filter("gform_field_value_discount_code", "populate_have_code");
    function populate_have_code($value){
        return $_SESSION['discount_code_s'];
    }
    Posted 11 years ago on Saturday February 23, 2013 | Permalink