• Hi, is there a way to pass the date fields Month/Day/Year data to another form’s date fields, specifically WSform?

    Looking to save users from needing to enter this information 2x.

    Thanks,
    Sol

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @soloant,

    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.

    Thanks
    Phil

    Thread Starter SoloAnt

    (@soloant)

    Hi @philsbury

    I heard back from the Form Dev and he said this:

    “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.
     
    e.g. https://mysite.com/my-page-with-form-on/?age_gate_m=1&age_gate_d=1&age_gate_y=1970″

    I don’t know if that would be the best way to do it or what you mentioned by way of js. or possibly this way with php here: https://wsform.com/knowledgebase/populate-the-default-value-of-a-field-using-php/

    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.

    Plugin Author Phil

    (@philsbury)

    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'));
    });
    Thread Starter SoloAnt

    (@soloant)

    Hi Phil, thank you for the insights here, I’ll play with this as soon as I can.

    Thanks again 👍

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Pass the Date Fields Data to another Form’ is closed to new replies.