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.

Neither "date" nor "confirm email" fields are pre-populating

  1. Jamie M
    Member

    Hi all,

    I'm implementing the methods described here: http://www.gravityhelp.com/forums/topic/little-hint-from-me-save-user-input-in-cookie-and-prepopulate-form

    Anyway, I can't get my date selector to pre-populate from the cookie. Perhaps because it's a date picker (drop-down day, month, year) and the following that I'm using might be wrong:

    add_filter("gform_field_value_date", "populate_date");
    function populate_date() {
    	return $_COOKIE["gf_date"];
    }

    Also, I'm using the following for the email. It works, but it only fills in the initial email entry, it leaves the confirm field empty:

    add_filter("gform_field_value_email", "populate_email");
    function populate_email() {
    	return $_COOKIE["gf_email"];
    }

    Help is greatly appreciated,
    James

    Posted 12 years ago on Monday February 27, 2012 | Permalink
  2. I have forwarded this forum post to Alex who will respond shortly.

    Posted 12 years ago on Tuesday February 28, 2012 | Permalink
  3. Hello James,
    The drop down date is posted as an array, so you need to serialize it when adding to the cookie, and then format it properly in your gform_field_value_XXX hook.

    Following is a code snippet to get you going.
    http://pastie.org/3482875

    As far as the confirmation email, you will need to use jQuery to do the trick. The easiest way to do that is to add an HTML block field to your form and paste the following code snippet in it. (Make sure to change the IDs to the appropriate values. See comments in the code snippet).
    http://pastie.org/3482898

    Posted 12 years ago on Tuesday February 28, 2012 | Permalink
  4. Jamie M
    Member

    Thanks very much, that worked perfectly. To check though, I was before using:
    setcookie("gf_".$field["inputName"], $_POST["input_" . $field["id"]], time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true);
    However I am now using your code:
    setcookie("gf_".$field["inputName"], $val);

    What's the most fundamental difference here? Anything I need to worry about?

    Posted 12 years ago on Wednesday February 29, 2012 | Permalink
  5. Jamie M
    Member

    .... I used backticks (`) but it didn't work

    Posted 12 years ago on Wednesday February 29, 2012 | Permalink
  6. If your WP install has some custom values for the cookie path and cookie domain, you should use the first call. If you haven't changed those values, the second (simpler) call should do the trick since it will just use default values for those variables.

    Posted 12 years ago on Wednesday February 29, 2012 | Permalink
  7. Jamie M
    Member

    Cool thanks :)

    One more thing...

    When I type in something like, Pak 'n Save, it will be repopulated via cookies as Pak \\\'n Save.

    Any idea how I can correct this? It will be a real nuisance when collating data.

    Posted 12 years ago on Thursday March 1, 2012 | Permalink
  8. try using stripslashes() when accessing the $_COOKIE variable.

    stripslashes($_COOKIE["gf_email"])
    Posted 12 years ago on Thursday March 1, 2012 | Permalink
  9. Jamie M
    Member

    Hi Alex,

    I used it like this:

    add_filter("gform_field_value_name", "populate_name");
    function populate_name() {
    	return stripslashes($_COOKIE["gf_name"]);
    }

    ... and it removed one slash. So the result was: Pak \'n Save

    Posted 12 years ago on Thursday March 1, 2012 | Permalink
  10. Jamie M
    Member

    Crap, another problem. I just changed my theme, and the code you gave me to fill in the 'confirm email' field no longer works. Any ideas? Is there another way to do this, perhaps in the functions.php file?

    PS: I've discovered that the new theme I'm using screws up the ampersand (&) character, therefore the JS above won't work. Also, many of my list items have "&" in them, so the conditional logic is also screwed up. Oh why can't life be easy :(

    Posted 12 years ago on Friday March 2, 2012 | Permalink
  11. Jamie M
    Member

    The issue on my second to last message was due to Magic Quotes. Disabled them, and now things are looking brighter.

    Posted 12 years ago on Friday March 2, 2012 | Permalink