防止用空输入提交表单? [英] prevent form submit with empty input?

查看:83
本文介绍了防止用空输入提交表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

如何防止提交HTML表单的输入字段值,如果它为空






 <?php 

include'../core/init.php ;
if(isset($ _ POST ['nt'])&& isset($ _ POST ['ntb'])){
mysql_query(INSERT INTO`post`(`myid`,`` (''。$ _ SESSION ['id']。','.mysql_real_escape_string($ _ POST ['nt'])。'));
}
?>

< iframe style =display:nonename =submissiontargetid =submissiontarget>< / iframe>
< form method =posttarget =submittargetaction =../ajax/post.phpname =form>
< input type =textboxname =ntclass =postwallid =ntplaceholder =贴在墙上rows =7wrap =physicalcols =40 onfocus =if(this.value =='贴在墙上')this.value =''; onblur =if(this.value =='')this.value ='贴在墙上'; />
< input type =submitstyle =display:none; name ='ntb'id ='ntb'class =Buttonchatvalue =发布/>
< / form>

我希望能够做到这一点,所以如果文本框是空白的,它说'他们是错误发布在你的墙上,请重试'。

解决方案

  if(isset($ _POST ['nt'])&& isset($ _ POST ['ntb'])){
...
} else {
echo请再试一次。;
}

在副本中捕获空输入提交是一个额外的功能,但你不会在服务器端执行。


Possible Duplicate:
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>

I want to be able to do it so if the textbox is blank it says, 'Their was an error posting on your wall, please try again'.

解决方案

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

The catching of empty input submits on clientside, as demonstrated in the duplicate, might be an additional feature, but you won't get around doing it serverside.

这篇关于防止用空输入提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆