Home  >  Article  >  Backend Development  >  Sharing of ajax form verification methods in TP framework

Sharing of ajax form verification methods in TP framework

小云云
小云云Original
2018-02-06 10:05:511480browse

This article mainly introduces the operation method of dynamic form verification and the ajax form verification problem in the TP framework. Friends in need can refer to it. I hope it can help everyone.

Operation method of dynamic verification

function yz()
  {
    if(empty($_POST))
    {
      $this->display();
    }
    else
    {
      $db=D("Info");
       
      $shu=array(
        array("Code","require","代号不能为空",0,"regex",3),
      );
       
      if(!$db->validate($shu)->create())
      {
        echo $db->getError();
      }
      else
      {
        echo"验证通过";
      }
    }
  }

Use ajax in the framework to enter the code and display the name. To enter the template, use the above

function ming()
  {
    $code=$_POST["code"];
    $db=D("Info");
    $data=$db->find($code);
    $name=$data["name"];
    $this->ajaxReturn($name,"eval");
  }

form

Code name:


js code