-5

可能重复:
如何防止提交 HTML 表单的输入字段值(如果它为空)

<?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>

我希望能够这样做,所以如果文本框是空白的,它会说,“他们在你的墙上发帖时出错,请再试一次”。

4

1 回答 1

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

如副本中所示,在客户端捕获空输入提交可能是一个附加功能,但您不会绕过在服务器端执行此操作。

于 2012-12-01T20:38:04.747 回答