當前位置:編程學習大全網 - 源碼下載 - jquery.validate.js 進行 remote 在tp框架中怎麽用

jquery.validate.js 進行 remote 在tp框架中怎麽用

remote有兩種方式,如下就介紹remote與PHP間的驗證

(1)meta String方式(當然這種方式要引入jquery.metadata.js)

以下是我的HTML代碼

<input type="text" name="moblie" id="jform_moblie" value=""

class="input {validate:{required:true,telphoneValid:

true,remote:'moblie_register.php?fun=moblie',

messages:{required:'請填寫手機號碼!',

telphoneValid:'請輸入正確的手機號',remote:'該手機號碼已被註冊!

<a href=login.php target=_blank>登錄?</a>'}}}" />

直接remote提交到PHP頁面中去。默認提交類型是GET方式提交

PHP代碼:

if ($_GET['fun']=='moblie') {//檢查手機是否已註冊

$moblie_number=trim($_GET['moblie']);

$exists_moblie=$db->query_first("select acc_moblie_number from t_account where

acc_moblie_number='".$moblie_number."'");

if (empty($exists_moblie['acc_moblie_number'])) {

$return['type']='true';

$return['info']='此手機號碼可註冊!';

}else{

$return['type']='false';

$return['info']='該手機號碼已被註冊!';

}

exit($return['type']);

}

這樣就完成的驗證

(2)rules方式

$("#Form2").validate({

rules: { //定義驗證規則,其中屬性名為表單的name屬性

"mail_account": {

required: true,

email: true ,

remote: {

url: '<--?php echo $this--->base;?-->/maileckmail',

type: 'POST',

dateType: 'json',

data: { mail_account:function(){

return $('#mail_account').val();

}

}

} },

},

messages: {

"mail_account": {

email: "請輸入正確的郵箱地址(例如 myemail@qq.com)",

remote: "該郵箱已存在!"

},

}

});

PHP代碼:

function checkMail(){

$mail_account = $_POST['mail_account'];

if($this->Mail->findByMailAccount($mail_account))

echo 'false';

else

echo 'true';

die();

}

  • 上一篇:王者榮耀阿軻全新套路玩法詳解 阿軻新套路怎麽玩
  • 下一篇:短視頻剪輯新規範
  • copyright 2024編程學習大全網