0
如何在發送前驗證表單數據?我有一個名爲address.php
的文件,它檢查輸入的數據以確保其符合要求。這裏是我的嘗試,但它沒有提交函數提交(我不想使用JS):在提交之前使用php文件驗證表單數據
function validate(){
include('checkaddress.php'); //checks data conforms
if (empty($_POST['address']) && checkAddress($_POST['address']) == 0)
{
echo ("<fieldset><legend>Invalid Address</legend><p id='form' style='color:red;'><b>Invalid Address </b></fieldset>");
return false;
}
else
{
return true;
}
}
<form method="post" action="address.php">
<fieldset>
<table style="float:center!improtant; text-align:center!important; margin-left:auto!important;margin-right:auto!important;">
<tr><legend>Address</legend></tr>
<tr><td>
<label for="email">address:</label>
<input type="text" name="address" id="address" size="32" maxlength="128">
</tr></td>
<tr><td>
<input type="submit" name="submit" onsubmit="return validate();" value="Submit" >
//Call function upon submit. I've tried 'onsubmit="validate();"'
</tr></td>
</table>
</fieldset>
</form>
謝謝。
如果您想在提交表單之前執行此操作,則必須使用javascript。 – jeroen 2014-10-20 21:39:03
在提交表單之前,無法在php中執行任何操作 - php在服務器上運行 – Steve 2014-10-20 21:39:19