Hi All,
I'm attempting to set cookies to populate a form based on this thread: http://www.gravityhelp.com/forums/topic/little-hint-from-me-save-user-input-in-cookie-and-prepopulate-form
I've hit a dead-end when it comes to having the cookie set on multi-input fields. The cookie sets just fine if the filed has a single value (email, phone, etc.) but when it comes to fields like Name (first and last) and Address (Address 1, Address 2, City, State, Zip, Country) the cookie just isn't setting at all.
Here's the code that I'm using to set the cookies:
add_action("gform_pre_submission", "pre_submission_handler");
function pre_submission_handler($form_meta) {
$saveVars = array("fname", "lname", "address", "addtwo", "phone", "email", "country", "state", "city", "zip");
foreach($form_meta["fields"] as $field) {
if (in_array($field["inputName"], $saveVars)) {
setcookie("gf_".$field["inputName"], $_POST["input_" . $field["id"]], time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true);
}
}
setcookie("gf_form_meta", serialize($form_meta['fields']), time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true);
}
Here are the filters:
add_filter("gform_field_value_fname", "populate_fname");
function populate_fname() {
return $_COOKIE["gf_fname"];
}
add_filter("gform_field_value_lname", "populate_lname");
function populate_lname() {
return $_COOKIE["gf_lname"];
}
add_filter("gform_field_value_address", "populate_address");
function populate_address() {
return $_COOKIE["gf_address"];
}
add_filter("gform_field_value_addtwo", "populate_addtwo");
function populate_addtwo() {
return $_COOKIE["gf_addtwo"];
}
add_filter("gform_field_value_phone", "populate_phone");
function populate_phone() {
return $_COOKIE["gf_phone"];
}
add_filter("gform_field_value_email", "populate_email");
function populate_email() {
return $_COOKIE["gf_email"];
}
add_filter("gform_field_value_country", "populate_country");
function populate_country() {
return $_COOKIE["gf_country"];
}
add_filter("gform_field_value_state", "populate_state");
function populate_state() {
return $_COOKIE["gf_state"];
}
add_filter("gform_field_value_city", "populate_city");
function populate_city() {
return $_COOKIE["gf_city"];
}
add_filter("gform_field_value_zip", "populate_zip");
function populate_zip() {
return $_COOKIE["gf_zip"];
}
I do have the fields set to populate dynamically and am passing the field parameters correctly (fname, lname, etc.)
Has anyone successfully gotten this to work? Any thoughts on how to pull it off?