enigmadigital / Formerly

Plugin to allow users to create custom forms within Craft CMS
MIT License
59 stars 24 forks source link

Stop submission when e-mail already registered #68

Closed Nexcapto closed 8 years ago

Nexcapto commented 8 years ago

Is this the right way to implement checking for duplicate e-mails? e.preventDefault doesn't actually get triggered since the function is called after the event's submit is called. I'm not really sure where to go from here.

$("#form").on('submit', function (e) {
        var temp;
        console.log($("#formtest_email").val());
        $.post('?ok=1', {
            action: 'formerly/submissions/alreadySubmitted',
            formid: $("input[name=formId]").val(),
            email: $("#formtest_email").val()
        },
        function(data, status){
            console.log("already?:" + data.alreadysubmitted + "\nStatus: " + data.ok);
            temp = data.alreadysubmitted;
            console.log(temp);

            if (temp == true) 
            {
                e.preventDefault();
                console.log("Got here");
            }
        });
    });