我正在使用一个php文件做一个dinamic表单,只显示和保存sql DB中的数据。现在我想要添加2个按钮NEXT和BEFORE。我正在尝试这样的事情但是没有显示按钮或者没有进入下一个/之前的屏幕。
if($inpageNew>0){
$url = "QUESTIONARECORRECT.php?screen=" . $onpageNew - 1;
echo <input class="botonsend" name="submit" type="submit" value="Before ←" >\n";
}
else if{
$url = "QUESTIONARECORRECT.php?screen=" . $onpageNew + 1;
echo "<input class="botonsend" name="submit" type="submit" value="Nest →" >\n";
}
并将网址放在<form id= "form1" method="post" action= "<?= $url; ?>" >
上。
我该怎么做?
答案 0 :(得分:0)
试试这个
<form method="post">
<?php
if (isset($_REQUEST['next']))
{
echo "<input class='botonsend' name='prev' type='submit' value='Before ←' >\n";
} else
{
echo "<input class='botonsend' name='next' type='submit' value='Nest →' >\n";
}
?>
</form>
答案 1 :(得分: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="← Before" <?php echo $form['b_disbled'];?>/><input type="submit" value="Next →" name="forward" <?php echo $form['f_disbled'];?>/></p>
</form>