How to realize the operation method of dynamic form verification and ajax form verification in TP framework
This article will explain in detail for you how to achieve dynamic form verification operations and TP framework inside the ajax form verification, editor feel very practical, so share to you to do a reference, I hope you can get something after reading this article.
Operation method of dynamic verification
Function yz () {if (empty ($_ POST)) {$this- > display ();} else {$db=D ("Info"); $shu=array (array ("Code", "require", "code cannot be empty", 0, "regex", 3),); if (! $db- > validate ($shu)-> create () {echo $db- > getError () } else {echo "verify passed";}
In the frame, use ajax to input the code, display the name and type the template.
Function ming () {$code=$_POST ["code"]; $db=D ("Info"); $data=$db- > find ($code); $name=$data ["name"]; $this- > ajaxReturn ($name, "eval");}
Form
Code name:
Js code
$(document) .ready (function (e) {$("# en") .click (function () {var code=$ ("# zhi"). Val (); $.ajax ({url: "_ _ CONTROLLER__/ming", data: {code:code}, type: "POST", dataType: "TEXT", success: function (data) {alert (data);}}) }) $("# yz") .blur (function () {var code=$ (this) .blur () $.ajax ({url: "_ _ CONTROLLER__/yan", data: {Code:code}, type: "POST", dataType: "TEXT", success: function (data) {if (data.trim () = = "ok") {$("# xs") .html ("Verification passed!") ; $("# xs"). Css ("color", "green");} else {$("# xs") .html (data); $("# xs") .css ("color", "red");});})})
Page display
Use ajax to make the error message of form validation be displayed directly behind.
Function yan () {$db=D ("Info"); $jieguo= ""; $shu=array (array ("Code", "require", "Code cannot be empty", 0, "regex", 3),); if (! $db- > validate ($shu)-> create ()) {$jieguo= $db- > getError ();} else {$jieguo= "ok" } $this- > ajaxReturn ($jieguo, "eval");}
Page display
On "how to achieve dynamic form verification operations and TP framework inside the ajax form verification" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.