-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>
我希望能夠做到這一點,所以如果文本框爲空,它說,「他們是在牆上的錯誤發帖,請再試一次'。
'if($ _POST ['nt'] ==「」){echo'error'; }' – sachleen
可能的重複[如何防止提交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
不難研究簡單網頁搜索中的基本表單驗證。在發佈問題之前,至少要付出一點努力 – charlietfl