0

我正在使用一个 php 文件做一个动态表单,它只显示和保存来自/在 sql DB 中的数据。现在我想添加 2 个按钮 NEXT 和 BEFORE 。我正在尝试这样的事情,但不显示按钮或不去下一个/之前的屏幕。

if($inpageNew>0){
$url = "QUESTIONARECORRECT.php?screen=" . $onpageNew - 1;
   echo <input class="botonsend" name="submit" type="submit"  value="Before &#8592"  >\n";
}
else if{

 $url = "QUESTIONARECORRECT.php?screen=" . $onpageNew + 1;
  echo "<input class="botonsend" name="submit" type="submit"  value="Nest &#8594"  >\n";
}

并将网址放在<form id= "form1" method="post" action= "<?= $url; ?>" >.

我怎样才能做到这一点 ?

4

2 回答 2

0

尝试这个

<form method="post">
    <?php
    if (isset($_REQUEST['next']))
    {
        echo "<input class='botonsend' name='prev' type='submit'  value='Before &#8592'  >\n";
    } else
    {
        echo "<input class='botonsend' name='next' type='submit'  value='Nest &#8594'  >\n";
    }
    ?>
</form>
于 2012-11-20T11:43:01.070 回答
0

如果您正在使用会话,则可以根据选择的按钮添加和减去计数。这样您就不需要将 $_GET 参数传递到您的 POST

<?php
session_start();

if(!isset($_SESSION['page'])){ $_SESSION['page']=0; }
if(isset($_POST['forward'])){  $_SESSION['page']++; }
if(isset($_POST['back'])){     $_SESSION['page']--; }

$form['f_disbled'] = null;
$form['b_disbled'] = null;

handle_post();

switch($_SESSION['page']){
    case 0:
        $page = 'Page 1';
        $form['b_disbled']='disabled="disabled"';
        break;

    case 1:
        $page = 'Page 2';
        break;

    case 2:
        $page = 'Page 3';
        break;

    case 3:
        $page = 'Page 4';
        break;

    case 4:
        $page = 'Page 5';
        $form['f_disbled']='disabled="disabled"';
        break;

    default:
        $page='Page Default';
        $form['f_disbled']='disabled="disabled"';
        unset($_SESSION['page']);
    break;
}

function handle_post(){
    if($_SERVER['REQUEST_METHOD']=='POST'){
        if(!empty($_POST['question'])){
            //Do somthing
        }
    }
}
?>

<form method="POST" action="">
  <p><?php echo $page;?> </p>
  <p>Question: <input type="text" name="question" size="20"></p>

  <p><input type="submit" name="back" value="&#8592 Before" <?php echo $form['b_disbled'];?>/><input type="submit" value="Next &#8594" name="forward" <?php echo $form['f_disbled'];?>/></p>
</form>
于 2012-11-20T11:44:58.463 回答