Get answers quicker by searching

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

GDPR tickbox on ajax form
  • Vote Up0Vote Down frankiefrankie
    Posts: 3Sendy user

    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

  • 8 Comments
  • Vote Up0Vote Down IanIan
    Posts: 26Sendy user

    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.

  • Vote Up0Vote Down frankiefrankie
    Posts: 3Sendy user

    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

  • Vote Up0Vote Down IanIan
    Posts: 26Sendy user

    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.

  • Vote Up0Vote Down frankiefrankie
    Posts: 3Sendy user

    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

  • Vote Up0Vote Down IanIan
    Posts: 26Sendy user

    @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?

  • Vote Up0Vote Down BenBen
    Posts: 3,537Sendy support

    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.

  • Vote Up0Vote Down IanIan
    Posts: 26Sendy user

    @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?

  • Vote Up0Vote Down IanIan
    Posts: 26Sendy user

    @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");
    }