SOLVED

Re: Custom Form Validation Using ZeroBounce

Go to solution
Ben_Bordofsky
Level 2

Re: Custom Form Validation Using ZeroBounce

Thanks for your help Sanford! I was able to get this to work and learned a bunch along the way. Here's the final snippet I used.

 

			  <!-- Start Marketo Form -->
			<script src="//url.marketo.com/forms2.min.js"></script> <form id="mktoForm_1234" class="mktoForm"></form>
			<script>

				MktoForms2.setOptions({ formXDPath : 'path goes here' });
				MktoForms2.loadForm("//url.marketo.com", "123-abc-789", 1234, function (form) {  //);

					  var theValidator = "first";
					  form.submittable(false);
					  form.onValidate(function(nativeValid) {

						//******* checks the built in validation *******
						if (!nativeValid) return;

						
						 //*******Checks the email using ZeroBounce ********//
						
						 /*Create variable for email address user input*/
						 var currentValues = form.getValues();
						 var emailToTest = currentValues.Email;

						 jQuery.get({
								url: ajaxurl,
								data:{"dataType":"json","action":"wordpress_function_name","email":emailToTest},
								 success: function (resp){
									if (theValidator == "first"){
									var emailObjForErrors = form.getFormElem().find("#Email");
										if (resp=="invalid"||resp == "unknown"||resp == "spamtrap"||resp == "abuse"||resp == "do_not_mail"){
											form.showErrorMessage("The email you've entered is invalid. Please try again.", emailObjForErrors);
										}
										else {
											form.submittable(true);
											theValidator = "second";
											form.submit();
										}
								}

							  else{
								  return;
							  }
							}
							}); //Get function ends

						});/*onValidate ends here*/

					}); //Form load ends

				</script> <!-- End Marketo Form -->

 

 

If anyone needs help setting up ZeroBounce + Wordpress + Marketo in the future and this thread doesn't solve it for you feel free to reach out... 🙂 

 

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Form Validation Using ZeroBounce

Nice work!

 

Though I would use a Boolean for theValidator (which I usually call is isExtendedValidatorComplete) instead of 2 magic Strings.