• Resolved amihaidany

    (@amihaidany)


    Hello,

    I’ve created a custom field, a checkbox.
    It’s not required, but if the user ticks it, i should know about it.

    I’m trying to get the custom field value in the ‘age_gate_form_success’ hook, but i see that the data that i’m getting using this hook, does not include the custom fields data.

    How can i get the custom field data after an age gate success?

    Thank you!

    • This topic was modified 5 years, 1 month ago by amihaidany.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @amihaidany,

    You should have it in the array that is passed to the filter. Take this as an example:

    
    add_filter('post_age_gate_custom_fields', 'my_custom_fields', 10, 1);
    
    function my_custom_fields($fields)
    {
        $fields .= '<label><input type="checkbox" name="ag_field_terms" value="1" /> I accept the terms and conditions</label>';
        return $fields;
    }
    
    add_filter('age_gate_form_success', function ($data) {
        // $data['ag_field_terms'] will be the checkbox
    });
    

    Of course, if it is not checked it won’t be int the POST data, so you’d been to check if it’s set in data:

    
    add_filter('age_gate_form_success', function ($data) {
        if (isset($data['ag_field_terms']) {
            // do stuff
        }
    });
    

    If you’re still having issues, feel free to post some code up and I’ll have a look

    Thanks
    Phil

    Thread Starter amihaidany

    (@amihaidany)

    Hello Phil,

    Thank you so much!
    So, now the ultimate question is – can i modify the AJAX response from server, after aan age gate has been passed successfully?

    Besides setting my own flags in the user session server side (after getting the custom fields data), i want to modify some elements in the same page, after the age gate passed. So i want to rely on the ‘agegatepassed’ JS event, and have the data of the custom fields inside the response.

    If that’s possible via hooks .. You just saved me whole lotta time! ??
    Didn’t find a hook of the JSON response though ??
    Thank you!

    • This reply was modified 5 years, 1 month ago by amihaidany.
    Plugin Author Phil

    (@philsbury)

    Hi @amihaidany,

    There’s no hooks for that at the moment (I’ll make a note though!), but when agegatepassed is triggered the form still exists so at that point you could do

    
    (function($){
      $(document).on('agegatepassed', function () {
        console.log($('.age-gate-form').serializeArray());
      });
    })(jQuery);
    

    and you’ll have all the form data

    Hope that helps

    Ta
    Phil

    Thread Starter amihaidany

    (@amihaidany)

    Hey Phil,

    Just wanted to say thank you so much once again, your support is amazing and i’m sure everyone here appreciate it. BIG UP!

    Amihai

    • This reply was modified 5 years, 1 month ago by amihaidany.
    • This reply was modified 5 years, 1 month ago by amihaidany.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Getting custom fields data after age gate success’ is closed to new replies.