Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the operation method of dynamic form verification and ajax form verification in TP framework

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report