サーバー側の検証がcheck.phpで完了するまで、ユーザーを「http://www.othersite.com」に送信することを「延期」(フォームのデフォルトの動作を停止)したい
完了したら、ユーザーを「http://www.othersite.com」に誘導します。検証ページには問題なく送信できますが、検証してから別の Web サイトに送信する必要があります。このようなフォームがあるとします
$(document).ready(function(){
$('#sendbutton').click(function(){
$('#error').empty();
$('#send').ajaxForm(function (data, textStatus) {
$('#error').append(data);
});
});
});
<form id="send" name="send" method="post" action="http://www.othersite.com/index.htm">
<input type="text" id="fname" name="fname" />
<input type="text" id="lname" name="lname" />
<input type="text" id="address" name="address" />
<input type="text" id="city" name="city" />
<input type="text" id="state" name="state" />
<button id="sendbutton">Submit</button>
</form>
<div id="error"></div>
サーバー側の検証はcheck.phpで行われます
check field inputs here on check.php
if not correct
echo error message
if successful echo "validation_ok"
返されたデータが「validation_ok」の場合、「http://www.othersite.com」でフォームの送信を完了するようユーザーに送信します。