2012-12-01 206 views
-6

可能重复:
How to prevent submitting the HTML form’s input field value if it empty防止用空输入提交表单?

<?php 

include '../core/init.php'; 
if(isset($_POST['nt']) && isset($_POST['ntb'])){ 
mysql_query("INSERT INTO `post` (`myid`, `text`) VALUES ('".$_SESSION['id']."', '".mysql_real_escape_string($_POST['nt'])."')"); 
} 
?> 

<iframe style="display:none" name="submissiontarget" id="submissiontarget"></iframe> 
<form method="post" target="submissiontarget" action = "../ajax/post.php" name="form"> 
<input type="textbox" name="nt" class="postwall" id="nt" placeholder="Post on your wall" rows="7" wrap="physical" cols="40" onfocus="if(this.value=='Post On Your Wall')this.value='';" onblur="if(this.value=='')this.value='Post On Your Wall';" /> 
<input type="submit" style="display:none;" name='ntb' id='ntb' class="Buttonchat"  value="Post" /> 
</form> 

我希望能够做到这一点,所以如果文本框为空,它说,“他们是在墙上的错误发帖,请再试一次'。

+0

'if($ _POST ['nt'] ==“”){echo'error'; }' – sachleen

+0

可能的重复[如何防止提交HTML表单的输入字段值,如果它为空](http://stackoverflow.com/questions/8029532/how-to-prevent-submitting-the-html-forms-input-字段值 - 如果它为空)(...或任何类似的问题在这里SO;例如http://stackoverflow.com/questions/10516122/how-prevent-submit-if-input-are-empty-with-javascript ) – feeela

+0

不难研究简单网页搜索中的基本表单验证。在发布问题之前,至少要付出一点努力 – charlietfl

回答

0
if(isset($_POST['nt']) && isset($_POST['ntb'])) { 
    … 
} else { 
    echo "There was an error posting on your wall, please try again."; 
} 

空输入的追赶提交关于客户方,如重复论证,可能是一个附加功能,但你不会得到周围做服务器端。