我有一個表單,如果電子郵件是錯誤的給我一個錯誤信息,而我留在同一頁上,這是可能的,因爲我用阿賈克斯。現在我試圖實現當我提交表單和返回是表單重置的錯誤。重置表單後提交
我試過reset();
但它沒有工作。
<?php
header("Refresh:7; url=contact.php");
$email = $_POST['subscribefield'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Dit emailadres klopt niet";
reset($email);
}
$to = "[email protected]";
$subject = "Abonee voor de nieuwsbrief";
$body = "$email \n Heeft zich aangemeld voor de nieuwsbrief";
mail($to, $subject, $body);
echo "U heeft zich zojuist aangemeld voor de vandenberg nieuwsbrief";
?>
和
$('form.subscribe').on('submit', function() {
var that = $(this),
url = that.attr('action'),
method = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value) {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type:method,
data: data,
success: function(response) {
$('#success-message').html(response).show();
setTimeout(function() {
$('#success-message').fadeOut('slow');
}, 2000);
}
});
return false;
});
你看了PHP手冊,復位功能是什麼? *將數組的內部指針設置爲其第一個元素*無論如何,我認爲您希望在表單submit上添加一個'event.preventDefault();'並將事件作爲參數添加到該js函數中。 – vaso123
如果您想要刪除POST電子郵件變量,請使用'unset($ _ POST ['subscribefield'])'代替。如果你想重置表單值:嘗試'$('。form.subscribe')[0] .reset();' –
@NachoM。沒有工作; _; –