扩展DesertIvy的答案,我认为如果您只是在表单完成验证后在网页上显示一条消息,那么用户的烦恼会少得多。它会不那么突兀。像这样的东西:
<form id="myForm" action="http://example.com/formSubmit.php" method="post">
<div>
<input type="text" name="name">
<input type="submit">
</div>
</form>
JavaScript:
function validForm() {
// form validation - return true or false
}
function submit_onclick() {
if(validForm()) {
$('#myForm').submit(); // this will submit the form to the form action
}
}
然后在加载 formSubmit.php 页面时,您可以在 HTML 正文中显示您的消息。这是如果您的服务器端语言是 PHP:
<?php
if(isset($_POST['name'])
echo "Thanks for completing the form " . $_POST['name'] . ".";
else
renderFormBody(); // function for rendering the form body
?>