[英]JavaScript not responsive before PHP (form action = "php file" onsubmit= " form’s fields validating function"
我已經在網上(包括 StackOverflow 例如)上調查了很長時間(太長),但沒有任何成功。 很多人都問了這個問題,但提出的解決方案中沒有一個對我有幫助。 所以無奈之下,我又回到了這個論壇。
<form id="myForm" method="post" action="updateMySQLGuests.php" onsubmit="return formSubmit()">
這個布爾結果函數在調用UpdateMySQLGuests.php
之前檢查字段的值是否正確(例如,驗證電子郵件是否包含@
)以在 MySQL 中通過 POST 方法使用這些表單字段的值創建記錄。 但是action= updateMySQLGuests.php
在formSubmit()
函數之前執行formSubmit()
實際上根本沒有執行)。 我在localhost
使用 Wampserver 工作。
您可以將表單的操作移動到formSubmit()
來解決此問題
<form id="myForm" method="post" onsubmit="return formSubmit()">
和formSubmit()
代碼:
function formSubmit() {
// the old code
...
// call submit form
document.getElementById('myForm').action = "updateMySQLGuests.php";
document.getElementById('myForm').submit();
}
<!-- in place of <form name= "myForm" id="myForm" action="updateMySQLGuests.php" method="post" onsubmit="return formSubmit()"> : -->
<form name="myForm" id="myForm" action="updateMySQLGuests.php" method="post">
<!-- action="updateMySQLGuests.php" -->
<label for="firstnames">Prénom:</label>
<input type="text" id="firstname" size="20" name="firstname"><br>
<label for="Lastnames">Nom:</label>
<input type="text" id="lastname" size="20" name="lastname" list="lstLastnames">
<datalist id="lstLastnames"> </datalist> <br>
<label for="email">E-mail:</label>
<input type="text" id="email" size="20" name="email"><br><br>
<!-- in place of <input type="submit" value="post"/> : -->
<button onclick="return validateValues()">Submit</button>
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.