【发布时间】:2012-11-19 17:58:00
【问题描述】:
可能重复:
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'; } -
How to prevent submitting the HTML form's input field value if it empty 的可能重复项(......或任何类似的问题在这里;例如stackoverflow.com/questions/10516122/…)
-
在简单的网络搜索中研究基本的表单验证并不难。在此处发布问题之前至少表现出一点努力
标签: php javascript jquery html css