检查表单是否提交并执行某些操作 [英] Check if form submitted and do something

查看:149
本文介绍了检查表单是否提交并执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的验证工作,但我只想输出它,当它已被提交,但isset或空虚似乎为我的工作原因?我使用php 5.5.3我相信我的代码:

 < form action =<?php echo $ _SERVER ['PHP_SELF'];?> method =postname =register> 
< input type =textplaceholder =Usernamemaxlength =15name =username/>< br>
< input type =passwordmaxlength =15name =password1/>< br>
< input type =passwordmaxlength =15name =password2/>< br>
< input type =textplaceholder =your@email.commaxlength =25name =email/>< br>
< input type =textmaxlength =20name =county/>< br>
< input type =submitvalue =Registernameregister/>
< / form>
<?php
//表单验证
if(empty($ _ POST ['register']))
{
echo选项A< br> ;
}
else
{
echoOption B< br>;
}

另外,我不记得如何输入相同的信息该用户,如果它证实罚款?

  value =<?php $ _POST ['stuff']?> 

注册名称注册/>
^

c $ c> = there。



应该是:

pre > < input type =submitvalue =Registername =register/>

使用 isset() 而不是 empty() ,在这种情况下:

  if(isset($ _ POST ['register']))
{
echoOption A< ;
}
else
{
echoOption B< br>;
}

我不确定选项A和B是什么,但通过此代码,您总是可以看到选项B 当你加载如果块中的条件将执行到 FALSE ,因此 else 块将被执行。如果你想避免这种情况,你可以使用 elseif 语句而不是 其他


I have got my validation working but I wanted to only output it, when it has been submitted but isset nor empty seems to work for me for some reason? I am using php 5.5.3 I believe

My code:

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="register">
    <input type="text" placeholder="Username" maxlength="15" name="username"/><br>
    <input type="password" maxlength="15" name="password1"/><br>
    <input type="password" maxlength="15" name="password2" /><br>
    <input type="text" placeholder="your@email.com" maxlength="25"  name="email"/><br>
    <input type="text" maxlength="20" name="county" /><br>
    <input type="submit" value="Register" name "register"/>
</form>
<?php
//Form Validation
if(empty($_POST['register']))
{
    echo "Option A <br>";
}
else
{
    echo "Option B <br>";
}

Also, I can't remember how I would enter in the same information for that user if it validates fine?

value="<?php $_POST['stuff'] ?>

解决方案

<input type="submit" value="Register" name "register"/>
                                          ^

You're missing an = there.

It should be:

<input type="submit" value="Register" name="register"/>

It's betterto use isset() instead of empty(), in this case:

if(isset($_POST['register']))
{
    echo "Option A <br>";
}
else
{
    echo "Option B <br>";
}

I'm not sure what Option A and B are, but with this code, you'll always see Option B when you load the page. The condition in your if block will execute to FALSE and hence the else block will executed. If you want to avoid this, you can use an elseif statement instead of an else.

这篇关于检查表单是否提交并执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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