jQuery UI Widgets › Forums › Plugins › Validator, Drag & Drop, Sortable › ajax validation problem
Tagged: validator
This topic contains 7 replies, has 3 voices, and was last updated by brio 9 years, 6 months ago.
-
Authorajax validation problem Posts
-
Hi,
I can’t find the way to let start ‘validationSuccess’ event when I’m validating with ajax.
In the code below, alert(‘You have filled the form correctly!’) doesn’t start.
What can I do?
Thanks in advance and happy new year.
Francesco<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>registrazione</title> <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" /> <link rel="stylesheet" href="jqwidgets/styles/jqx.classic.css" type="text/css" /> <script type="text/javascript" src="scripts/gettheme.js"></script> <script type="text/javascript" src="scripts/jquery-1.10.1.min.js"></script> <script type="text/javascript" src="scripts/jquery.caret.js"></script> <script type="text/javascript" src="jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="jqwidgets/jqxexpander.js"></script> <script type="text/javascript" src="jqwidgets/jqxinput.js"></script> <script type="text/javascript" src="jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="jqwidgets/jqxdropdownlist.js"></script> <script type="text/javascript" src="jqwidgets/jqxnumberinput.js"></script> <script type="text/javascript" src="jqwidgets/jqxvalidator.js"></script> <script type="text/javascript" src="jqwidgets/jqxbuttons.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#testForm').jqxValidator({ rules: [{ input: '#userInput', message: 'Username is required!', action: 'blur', rule: 'required' }, {input: '#telefono_cellulare123', message: 'numero telefonico non valido.', action: 'blur', rule: function(input, commit) { var telefono_cellulare = $('#telefono_cellulare123').val(); if (telefono_cellulare.length == 10) { $.ajax({ url: "valida_telefono_cellulare.php", type: 'POST', data: {telefono_cellulare: telefono_cellulare}, success: function(data) { if (data == "true") { commit(true); } else commit(false); }, error: function() { commit(false); } }); } else if (telefono_cellulare.length == 0) { return true; } else { return false; } } }] }); $("#jqxbutton").jqxButton({ theme: 'energyblue', width: 100, height: 30 }); $('#testForm').on('validationSuccess', function(event) { alert('You have filled the form correctly!') }); $("#jqxbutton").click(function() { $('#testForm').jqxValidator('validate'); }); }); </script> <form id="testForm" action="./"> <table class="register-table"> <tr> <td>Username:</td> <td> <input type="text" id="userInput" class="text-input" /> </td> </tr> <tr> <td>mobile:</td> <td> <input type="text" id="telefono_cellulare123" class="text-input" /> </td> </tr> </table> </form> <input type="button" style="margin: 10px;" id="jqxbutton" value="Submit" />
Hi brio,
If the event is not raised, may be the validation has Failed. Here’s a sample with Ajax Validation – http://www.jqwidgets.com/jquery-widgets-demo/demos/php/registration_form.htm?arctic and the validationSuccess event.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi Peter,
thanks for answering.
I checked everything (I think) in my code, that’s similar to your example.
When validation fails, a red pop up informs me.
I tried even the opposite validation answer “validationError” (*).
In both case alert() doesn’t start.best regard,
Brio*)
$('#testForm').on('validationSuccess', function(event) { alert('You have filled the form correctly!') });
brio,
Did you ever get this working? I’m having the similar problem and not been able to find a working solution.
– Mike
Hi mikemazz,
you may take a look at the PHP demos which have Validator with Ajax vavlidation.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/dear Peter,
it’s me again; still with this problem.
‘validationSuccess’ works only when I cut off ajax rule.
Php rule works fine, I think.
I would like to show you some code abstract.$('#registrationForm').jqxValidator({ hintType: 'label', rules: [ {input: '#nome', message: 'campo obbligatorio.', action: 'blur', rule: 'required'}, {input: '#nome', message: 'almeno 2 caratteri.', action: 'blur', rule: 'minLength=2'}, {input: '#cognome', message: 'campo obbligatorio.', action: 'blur', rule: 'required'}, {input: '#cognome', message: 'almeno 2 caratteri.', action: 'blur', rule: 'minLength=2'}, {input: '#codicefiscale', message: 'campo obbligatorio.', action: 'blur', rule: 'required'}, {input: '#codicefiscale', message: 'codice fiscale non valido.', action: 'blur', rule: function (input, commit) { var cf = $('#codicefiscale').val(), validi, i, s, set1, set2, setpari, setdisp; if (cf == '') return ''; cf = cf.toUpperCase(); if (cf.length != 16) return false; validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; for (i = 0; i < 16; i++) { if (validi.indexOf(cf.charAt(i)) == -1) return false; } set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ"; setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX"; s = 0; for (i = 1; i <= 13; i += 2) s += setpari.indexOf(set2.charAt(set1.indexOf(cf.charAt(i)))); for (i = 0; i <= 14; i += 2) s += setdisp.indexOf(set2.charAt(set1.indexOf(cf.charAt(i)))); if (s % 26 != cf.charCodeAt(15) - 'A'.charCodeAt(0)) return false; return true; } }, {input: '#comune', message: 'campo obbligatorio.', action: 'blur', rule: 'required'}, {input: '#comune', message: 'campo obbligatorio.', action: 'blur', rule: 'minLength=2'}, {input: '#indirizzo', message: 'campo obbligatorio.', action: 'blur', rule: 'required'}, {input: '#indirizzo', message: 'almeno 2 caratteri.', action: 'blur', rule: 'minLength=2'}, {input: '#telefonofisso123', message: 'numero telefonico non valido.', action: 'blur', rule: function (input, commit) { var telefonofisso = $('#telefonofisso123').val(); if (telefonofisso.length >= 7) { switch (telefonofisso.substr(0, 2)) { case "00": if (telefonofisso.substr(0, 3) == "004") { //004 è il prefisso di Campione d'Italia return true; } else { return false; } break; default: if (telefonofisso.substr(0, 1) == "0") { return true; } else { return false; } break; } } else if (telefonofisso.length == 0) { return true; } else { return false; } ; } }, {input: '#telefonocellulare123', message: 'campo obbligatorio.', action: 'blur', rule: 'required'}, //{input: '#telefonocellulare123', message: 'numero telefonico non valido.', action: 'blur', rule: 'minLength=9'}, {input: '#telefonocellulare123', message: 'numero telefonico non valido.', action: 'blur', rule: function (input, commit) { var telefonocellulare = $('#telefonocellulare123').jqxInput('val'); if (telefonocellulare.length == 10) { $.ajax({ type: 'POST', url: "valida_telefono_cellulare.php", //dataType: 'html', data: {telefono_cellulare: telefonocellulare}, success: function (data) { if (data == "true") { commit(true); } else commit(false); }, error: function () { commit(false); } }); } else if (telefonocellulare.length == 0) { return true; } else { return false; } } }, {input: '#email', message: 'campo obbligatorio.', action: 'blur', rule: 'required'}, {input: '#email', message: 'indirizzo email non valido.', action: 'blur', rule: function (input, commit) { var email = $('#email').jqxInput('val'); $.ajax({ type: 'POST', url: "valida_email.php", //dataType: 'html', data: {email: email}, success: function (data) { if (data == "true") { commit(true); } else commit(false); }, error: function () { commit(false); } }); } }, {input: '#password', message: 'campo obbligatorio.', action: 'blur', rule: 'required'}, {input: '#password', message: 'la password dev\'essere compresa tra 6 e 12 caratteri.', action: 'blur', rule: 'length=6,12'}, {input: '#conferma_password', message: 'campo obbligatorio.', action: 'blur', rule: 'required'}, {input: '#conferma_password', message: 'non c\'è corrispondenza con la password.', action: 'blur', rule: function (input, commit) { // call commit with false, when you are doing server validation and you want to display a validation error on this field. if (input.val() === $('#password').val()) { return true; } return false; }} ], theme: theme }); $('#registrationForm').on('validationSuccess', function (event) { alert(); // alert('You have filled the form correctly!') // $.post("registrazione.php", $("#registrationForm").serialize(), function(result) { // $("span").html(result); // }); // $("span").html($("#registrationForm").serialize()); $.post("registrazione.php", { nome: $('#nome').val(), cognome: $('#cognome').val(), codicefiscale: $('#codicefiscale').val(), comune: $('#comune').val(), indirizzo: $('#indirizzo').val(), cap: $('#cap').val(), telefonofisso: $('#telefonofisso123').val(), telefonocellulare: $('#telefonocellulare123').val(), email: $('#email').val(), password: $('#password').val(), ip: $('#ip').val() }, function (result) { $("#windowsMessage").html(result); $('#eventWindow').jqxWindow('open'); }); }); $('#sendButton').jqxButton({width: 100, height: 25, theme: theme}); $("#sendButton").click(function () { $('#registrationForm').jqxValidator('validate'); });
<?php function disposablecheck($telefono_cellulare) { $whitelist = array( "313", "320", "322", "323", "324", "327", "328", "329", "330", "331", "334", "335", "336", "337", "338", "339", "340", "341", "342", "343", "345", "346", "347", "348", "349", "350", "351", "360", "361", "362", "363", "366", "368", "370", "373", "375", "377", "380", "383", "388", "389", "390", "391", "392", "393", "397" ); $telefono_cellulare_prefisso = substr($telefono_cellulare, 0, 3); if (in_array($telefono_cellulare_prefisso, $whitelist)) { return 0; } else { return 1; } } $cellulare = $_POST["telefono_cellulare"]; //if (disposablecheck($_POST["telefono_cellulare"]) == 1) { if (disposablecheck($cellulare) == 1) { //do stuff for disposable emails echo "false"; return; } else { //do stuff if not disposable email echo "true"; return; } ?>
<?php function disposablecheck($email) { $blacklist = array( "0815.ru0clickemail.com", "0wnd.net", "0wnd.org", "10minutemail.com", "20minutemail.com", "2prong.com", "3d-painting.com", "4warding.com", "4warding.net", "4warding.org", "9ox.net", "a-bc.net", "amilegit.com", "anonbox.net", "anonymbox.com", "antichef.com", "antichef.net", "antispam.de", "baxomale.ht.cx", "beefmilk.com", "binkmail.com", "bio-muesli.net", "bobmail.info", "bodhi.lawlita.com", "bofthew.com", "brefmail.com", "bsnow.net", "bugmenot.com", "bumpymail.com", "casualdx.com", "chogmail.com", "cool.fr.nf", "correo.blogos.net", "cosmorph.com", "courriel.fr.nf", "courrieltemporaire.com", "curryworld.de", "cust.in", "dacoolest.com", "dandikmail.com", "deadaddress.com", "despam.it", "devnullmail.com", "dfgh.net", "digitalsanctuary.com", "discardmail.com", "discardmail.de", "disposableaddress.com", "disposemail.com", "dispostable.com", "dm.w3internet.co.uk example.com", "dodgeit.com", "dodgit.com", "dodgit.org", "dontreg.com", "dontsendmespam.de", "dump-email.info", "dumpyemail.com", "e4ward.com", "email60.com", "emailias.com", "emailinfive.com", "emailmiser.com", "emailtemporario.com.br", "emailwarden.com", "ephemail.net", "explodemail.com", "fakeinbox.com", "fakeinformation.com", "fastacura.com", "filzmail.com", "fizmail.com", "frapmail.com", "garliclife.com", "get1mail.com", "getonemail.com", "getonemail.net", "girlsundertheinfluence.com", "gishpuppy.com", "great-host.in", "gsrv.co.uk", "guerillamail.biz", "guerillamail.com", "guerillamail.net", "guerillamail.org", "guerrillamail.com", "guerrillamailblock.com", "haltospam.com", "hotpop.com", "ieatspam.eu", "ieatspam.info", "ihateyoualot.info", "imails.info", "inboxclean.com", "inboxclean.org", "incognitomail.com", "incognitomail.net", "ipoo.org", "irish2me.com", "jetable.com", "jetable.fr.nf", "jetable.net", "jetable.org", "junk1e.com", "kaspop.com", "kulturbetrieb.info", "kurzepost.de", "lifebyfood.com", "link2mail.net", "litedrop.com", "lookugly.com", "lopl.co.cc", "lr78.com", "maboard.com", "mail.by", "mail.mezimages.net", "mail4trash.com", "mailbidon.com", "mailcatch.com", "maileater.com", "mailexpire.com", "mailin8r.com", "mailinator.com", "mailinator.net", "mailinator2.com", "mailincubator.com", "mailme.lv", "mailnator.com", "mailnull.com", "mailzilla.org", "mbx.cc", "mega.zik.dj", "meltmail.com", "mierdamail.com", "mintemail.com", "moncourrier.fr.nf", "monemail.fr.nf", "monmail.fr.nf", "mt2009.com", "mx0.wwwnew.eu", "mycleaninbox.net", "mytrashmail.com", "neverbox.com", "nobulk.com", "noclickemail.com", "nogmailspam.info", "nomail.xl.cx", "nomail2me.com", "no-spam.ws", "nospam.ze.tc", "nospam4.us", "nospamfor.us", "nowmymail.com", "objectmail.com", "obobbo.com", "onewaymail.com", "ordinaryamerican.net", "owlpic.com", "pookmail.com", "proxymail.eu", "punkass.com", "putthisinyourspamdatabase.com", "quickinbox.com", "rcpt.at", "recode.me", "recursor.net", "regbypass.comsafe-mail.net", "safetymail.info", "sandelf.de", "saynotospams.com", "selfdestructingmail.com", "sendspamhere.com", "shiftmail.com", "****mail.me", "skeefmail.com", "slopsbox.com", "smellfear.com", "snakemail.com", "sneakemail.com", "sofort-mail.de", "sogetthis.com", "soodonims.com", "spam.la", "spamavert.com", "spambob.net", "spambob.org", "spambog.com", "spambog.de", "spambog.ru", "spambox.info", "spambox.us", "spamcannon.com", "spamcannon.net", "spamcero.com", "spamcorptastic.com", "spamcowboy.com", "spamcowboy.net", "spamcowboy.org", "spamday.com", "spamex.com", "spamfree24.com", "spamfree24.de", "spamfree24.eu", "spamfree24.info", "spamfree24.net", "spamfree24.org", "spamgourmet.com", "spamgourmet.net", "spamgourmet.org", "spamherelots.com", "spamhereplease.com", "spamhole.com", "spamify.com", "spaminator.de", "spamkill.info", "spaml.com", "spaml.de", "spammotel.com", "spamobox.com", "spamspot.com", "spamthis.co.uk", "spamthisplease.com", "speed.1s.fr", "suremail.info", "tempalias.com", "tempemail.biz", "tempemail.com", "tempe-mail.com", "tempemail.net", "tempinbox.co.uk", "tempinbox.com", "tempomail.fr", "temporaryemail.net", "temporaryinbox.com", "thankyou2010.com", "thisisnotmyrealemail.com", "throwawayemailaddress.com", "tilien.com", "tmailinator.com", "tradermail.info", "trash2009.com", "trash-amil.com", "trashmail.at", "trash-mail.at", "trashmail.com", "trash-mail.com", "trash-mail.de", "trashmail.me", "trashmail.net", "trashymail.com", "trashymail.net", "tyldd.com", "uggsrock.com", "wegwerfmail.de", "wegwerfmail.net", "wegwerfmail.org", "wh4f.org", "whyspam.me", "willselfdestruct.com", "winemaven.info", "wronghead.com", "wuzupmail.net", "xoxy.net", "yogamaven.com", "yopmail.com", "yopmail.fr", "yopmail.net", "yuurok.com", "zippymail.info", "jnxjn.com", "trashmailer.com", "klzlk.com", ); $email_split = explode('@', $email); $email_domain = $email_split[1]; if (in_array($email_domain, $blacklist)) { //Return 1, disposable email detected return 1; } else { //Return 0, no match found return 0; } } $email = $_POST["email"]; if (validEmail($email) == true) { if (disposablecheck($email) == 1) { //do stuff for disposable emails echo "false"; } else { //do stuff if not disposable email echo "true"; }; return; } else { echo "false"; return; }; function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex + 1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { // local part length exceeded $isValid = false; } else if ($domainLen < 1 || $domainLen > 255) { // domain part length exceeded $isValid = false; } else if ($local[0] == '.' || $local[$localLen - 1] == '.') { // local part starts or ends with '.' $isValid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) { $isValid = false; } } if ($isValid && !(checkdnsrr($domain, "MX") || checkdnsrr($domain, "A"))) { // domain not found in DNS $isValid = false; } } return $isValid; } ?>
Any suggest?
Thanks and best regards
BrioHi brio,
This demo: http://www.jqwidgets.com/jquery-widgets-demo/demos/php/registration_form.htm?arctic demonstrates how to use this widget with AJAX validation.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comDear Peter,
I look at that demo many and many times.
On my code ajax validations work fine but validationSuccess event doesn’t start.
I really don’t know what to do 🙁
Have you got some suggests more, please? -
AuthorPosts
You must be logged in to reply to this topic.