Skip to content

GDPR tickbox on ajax form

edited January 2020 in Questions

Hi,

I have been trying to add a GDPR compliant checkbox/tickbox to the ajax signup form without success and wondered if anyone else has done it successfully (including validation) and can share their code please.

Thanks

Comments

  • IanIan
    edited January 2020

    If you don't mind letting us see a simplified version of your code, we could help you debug more easily by checking the simplified code.

  • edited January 2020

    H Ian,
    the code is the one supplied by Sendy on this page - https://sendy.co/api
    It's the "Subscribe via AJAX" whic links to this download - https://dl.dropboxusercontent.com/s/6ilix20ri3l3esu/Subscribe via AJAX.zip?token_hash=AAEE0bgEBCgeihVg1gVfCUpJ4hFKtWb0lqPfJiTFCJbSpQ&dl=1
    Thanks

  • IanIan
    edited January 2020

    The "Subscribe via AJAX" demo does not have a GDPR checkbox. Please let us know how you added the GDPR checkbox in your code so that we could help debug.

  • Hi Ian, I haven't added one, that's what I want to do and wondered if anyone else had done it and could share their code to achieve this as it's a pretty standard requirement now for all forms.
    Thanks

  • IanIan
    edited January 2020

    @Ben, Currently, the API does not echo an error message when the GDPR checkbox is not checked. Could you please make it echo an error message when the GDPR checkbox is not checked?

  • If you are coding a custom form that utilizes the 'subscribe' API, you'd need to write code to validate any additional inputs via your backend code before calling the 'subscribe' API.

  • IanIan
    edited January 2020

    @Ben, Thanks. Currently, only Ready-to-Use Subscribe Forms display the Consent not given. message when the GDPR checkbox is not checked. Would you please consider making that message one of the built-in messages of the Subscribe API in a future release?

  • IanIan
    edited January 2020

    @frankie, In the mean time, you may implement the feature by:

    1. Adding a checkbox in the HTML (with a label element, of course):

    <input type="checkbox" name="gdpr" id="gdpr">
    



    2. Adding this if statement at the beginning of the PHP:

    if ($_POST['gdpr'] != 'true')
    {
        exit('Consent not given.');
    }
    



    3. Adding this new key/value pair into the $postdata array in the PHP:

    'gdpr' => 'true'
    



    4. Adding this new line as the line 8 in the JavaScript:

    gdpr = $form.find('input[name="gdpr"]').is(':checked') ? 'true' : 'false',
    



    5. Changing the line 11 of the JavaScript to:

    $.post(url, {name:name, email:email, gdpr:gdpr},
    



    6. And then adding this else if statement among the existing ones in the JavaScript:

    else if(data=="Consent not given.")
    {
        $("#status").text('Please check the "Marketing permission" checkbox.'); // You can modify this message.
        $("#status").css("color", "red");
    }
    
This discussion has been closed.