iT邦幫忙

0

jQuery validate false 不阻擋

請問使用jQuery steps並用validate remote來驗證輸入的資訊是否正確

如果驗證失敗(回傳false)有辦法顯示提示訊息
但仍可點選下一步嗎?

form.validate({
    errorPlacement: function errorPlacement(error, element) {element.before(error); },
		rules: {
			ProductID: {
				required: true,
				remote: {
					url:URL,
					type: "POST",
					dataType: "json",
					data: {
						ProductID : function(){
							return $('#ProductID').val();
                        }
					}
				}
            }
        }
});

PHP URL

<?php
header("Content-Type:text/html; charset=utf-8");

$CheckProductID = $_POST['ProductID'];

$checkSQL = "SELECT * FROM Table WHERE ProductID = '".$CheckProductID."'";
$result = mysqli_query($conn,$checkSQL);

// Check ProductID exist or not
if (mysqli_num_rows($result) > 0) {
	echo json_encode('ProductID已存在!');
	echo false;
}else {
	echo true;
}
$conn->close();
?>

基本上我是希望 如果使用者輸入的ProductID已經存在
會秀出提示訊息 但仍可以下一步繼續填寫

因為好像要回傳false才有辦法秀出訊息
但我又想讓USER繼續下一步

再請各位指教

謝謝 !

[Update]
整理需求:

  1. 特定欄位(ProductID)如果驗證錯誤(顯示訊息) 仍可以點選step的下一步
  2. 或是特定欄位(ProductID)如果驗證成功 也可以顯示訊息
    主要是想讓ProductID欄位如果判斷已經存在 會提示USER 但仍可繼續作業
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
WilliamHuang
iT邦研究生 1 級 ‧ 2018-08-15 18:33:38

$conn->close();
呼叫你想回去的那個函式
就會無窮迴圈了
這樣我建議要加個離開的按鈕
/images/emoticon/emoticon34.gif

Neish iT邦研究生 1 級 ‧ 2018-08-16 08:04:49 檢舉

WilliamHuang 什麼意思? 煩請大大解惑 謝謝!

0

這樣…

form.validate({
    errorPlacement: function errorPlacement(error, element) {element.before(error); },
		rules: {
			ProductID: {
				required: true,
				remote: {
					url:URL,
					type: "POST",
					dataType: "json",
					data: {
						ProductID : function(){
							return $('#ProductID').val();
                        }
					}
				}
            }
        },
	highlight: function(element, errorClass) {
		alert('error');
	}
});
Neish iT邦研究生 1 級 ‧ 2018-08-16 10:03:58 檢舉

跟著鄉民看熱鬧 我用highlight還是會卡控... 沒辦法下一步

請問如果是驗證成功 仍顯示訊息呢? (只有特定欄位顯示成功訊息)

https://dotblogs.com.tw/wadehuang36/2010/08/22/17353
showErrors 訊息顯示的Callback,只要有事件發生都會被呼叫,包含驗證成功。

我要發表回答

立即登入回答