Skip to content

Instantly share code, notes, and snippets.

@umair-khokhar
Last active June 5, 2017 18:41
Show Gist options
  • Save umair-khokhar/ab7ef9847880e0026815bc2540d79325 to your computer and use it in GitHub Desktop.
Save umair-khokhar/ab7ef9847880e0026815bc2540d79325 to your computer and use it in GitHub Desktop.
<div class="form-container">
{% form "my_form" form_to_use='form-ID', title='Free Trial', response_response_type='inline', response_message='Thanks!' %}
<div class="disclaimer" style="text-align:center">By clicking "Apply Now" you agree that you've read and accepted <a href ="http://www.1800approved.com.au/privacy-policy-new/" target="_blank">Privacy Policy/Consent</a> and <a href = "http://www.1800approved.com.au/credit-guide-quote/" target="_blank">Credit Guide Quote</a>.
</div>
</div>
<script>
$(function() {
setTimeout(function() {
var fID = $(".form-container").find("form").attr("id");
var form = document.getElementById(fID);
form.addEventListener('submit', function(event) {
event.preventDefault();
var email = $("#" + fID + " input[name='email']").val();
var phone = $("#" + fID + " input[name='phone']").val();
var url = "http://dev.1800approved.com.au/api/v1/field/validate?type=email&field=email_address&value="+email;
$.ajax({
url: url,
dataType: "jsonp",
success: function(r) {
if(r.email_exists == "VALID" || r.email_exists == "UNKNOWN" ) {
var url2 = "http://dev.1800approved.com.au/api/v1/field/validate?type=phone&field=number&value="+phone;
$.ajax({
url: url2,
dataType: "jsonp",
success: function(r) {
if(r.phone_status == "Active" || r.phone_status == "Unknown") {
setTimeout(function() {
form.submit();
}, 2000);
} else {
alert("Phone number is inactive!")
}
}
});
} else {
alert("Email address doesn't exists!")
return;
}
}
});
});
}, 2000);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment