1
<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";
    }
}

我想做的很简单,在表单操作中我希望操作为 action="#" 如果尚未满足 if 条件并且如果满足,则操作将为 action="add_new_item2.php?user_id=123"

4

4 回答 4

1

试试这个

<?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"> 
于 2012-10-27T04:12:46.767 回答
1

你在使用前制造条件意味着......

<?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">
于 2012-10-27T04:28:41.580 回答
0

如果已经设置了重定向值。用于$_SERVER['PHP_SELF']对当前页面进行操作。

检查报价$redirect == "f"。它应该是单引号或正确转义。

<form name="form1" method="post" 
      action="<?php 
             if(isset($redirect)&& $redirect == 'f'){echo $_SERVER['PHP_SELF'];} 
             else{ echo 'add_new_item2.php?user_id='.$_GET['user_id']; }
            ?>"
>
于 2012-10-27T04:15:34.407 回答
0

尝试在双引号前后加上单引号。与此类似:

<input type=label name=\"Description1\" value='". $T_Description. "' style=\"width:650px; margin-left:50px; padding: 5px;\" \>

(value = '" x " ' ) 希望这会有所帮助...

于 2017-05-12T13:30:44.417 回答