Yes you can use the age_gate/submission/success action which should give you all the fields if using inputs/selects
add_action('age_gate/submission/success', function($data) {
// data contains:
// $data['age_gate_d']
// $data['age_gate_m']
// $data['age_gate_y']
// you can store these how you need
});
There’s also the potential to do it just in JS, but I’m not sure how you want to implement it with your forms.
“You would need to ask them how it can pass query string variables to the page containing your form in order for the #query_var variable to work. #query_var will only return a value if those elements existing in a query string in the URL of the page your form is on.
I’m looking to pass off the mm/dd/yyyy data from age-gate into a single text field like this on the next page where the form is so a user doesn’t have to enter the DOB two times.
I think you’ll have to test a couple of options here, but I’d be leaning towards a custom JS approach as:
Option 1 – you’d have to find an manipulate any links to the page with your form on, probably via JS if you’re caching anyway which feels like more work
Option 2 – does setting the default happen over AJAX/REST/Similar as if not, it’ll probably cache the first response.
I think this is how I’d do it – all demo so give it a good test if you haven’t got a solution already:
PHP:
add_action('age_gate/submission/success', function($data) {
// data contains:
// $data['age_gate_d']
// $data['age_gate_m']
// $data['age_gate_y']
// you can store these how you need
// lets just store this in YYYY-MM-DD for the sake of a demo
// This should work for all instances - unless you are on the form page itself perhaps
setcookie('dob', sprintf('%s-%s-%s', $data['age_gate_y'], $data['age_gate_m'], $data['age_gate_d']), 0, '/');
});
Then in JS:
// lifted from the internet so just a demo.
function getCookie(name) {
let cookie = {};
document.cookie.split(';').forEach(function (el) {
let split = el.split('=');
cookie[split[0].trim()] = split.slice(1).join("=");
})
return cookie[name];
}
window.addEventListener('DOMContentLoaded', () => {
// if the form is loaded in after the fact (like ninja forms do), there may be a different event to use above
document.querySelectorAll('selector of your form field').forEach(field => field.value = getCookie('dob'));
});