我需要使用php和javascript驗證空字段,但兩種方法都失敗。使用php驗證空字段
<form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<input type="text" name="pickupaddress" value="<?
if($pickupaddress == ''){
echo "";}
else{echo htmlentities($pickupaddress);}?> " id="pickupaddress"/>
<input type ="submit" name="submit" value"Reserve"/>
</form>
//////// Php validation DOES NOT WORK////////
$pickupaddress ='';
$err ='';
$pickupaddress = $_POST['pickupaddress'];
if($pickupaddress == ''){ //if empty field, I also tried == ""
$err.="Please provide pick up address.";
}
///// Javascript validation does not work.
if(form.pickupaddress ==""){
alert("empty address!");
}
//當我點擊提交沒有任何反應。 //我想這個問題是
htmlentities($pickupaddress);
//感謝您的幫助。
var_dump($ _ POST ['pickup地址']);回報什麼? – 2012-08-13 22:25:55
java!= javascript。 – Hamish 2012-08-13 22:35:25
您的拾取地址字段值的值有空白。 ..因爲''!=''您的驗證器永遠不會工作。 – 2012-08-13 22:40:45