有条件地设置表单提交动作 [英] Conditionally set form submit action

查看:122
本文介绍了有条件地设置表单提交动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form action =<?php if(isset($ redirect)&& $; redirect ==f){echo#;} 
else {?> add_new_item2.php?user_id =<?php echo $ _GET ['user_id'];}?>方法= POST >
//无需在此处显示此区域
< input type =submitvalue =submitname =submit/>
< / form>
$ b $ //处理器

<?php
if(isset($ _ POST ['submit']))
{
$ redirect =f;
if(whatever)
{
// if条件到达
}
else //所有条件满足
{
$ redirect =t;




$ b $ p
$ b

我想要做的事情很简单,如果if条件尚未满足,并且符合要求,动作将为action =add_new_item2.php?user_id = 123,我希望该动作为action =#。

解决方案

试试这个

 <?php 
$ action ='';
if(isset($ redirect)&& $; redirect ==f){
$ action =#;
} else {
$ action =add_new_item2.php?user_id =。$ _ GET ['user_id'];
}
?>
< form action =<?php echo $ action;?>方法= POST >


<form action="<?php if(isset($redirect)&& $redirect == "f"){echo "#";} 
else{ ?>add_new_item2.php?user_id=<?php echo $_GET['user_id']; }?>" method="post"> 
//no need to expose this area here
<input type="submit" value="submit" name="submit" />
</form>

//the processor

<?php 
if(isset($_POST['submit']))
{
$redirect = "f";
    if(whatever)
    {
     //the if condition comes here
    }
    else //all if conditions are satisfied
    {
       $redirect = "t";
    }
}

What i want to do is simple in the form action i want the action to be action="#" if the if conditions are not yet met and if they are met the action will be action="add_new_item2.php?user_id=123"

解决方案

try this

<?php
$action = ''; 
if(isset($redirect) && $redirect == "f") {
  $action = "#";
} else {
  $action = "add_new_item2.php?user_id=".$_GET['user_id'];
}
?>
<form action="<?php echo $action; ?>" method="post"> 

这篇关于有条件地设置表单提交动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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