我有一个index.php和output.php 我需要两个按钮链接到output.php但不同的功能,我不能让它工作。这是我的代码:
在index.php中:
<?php
include 'output.php';
if (isset ($_POST ['choice3'])){
choice3();
}
if (isset ($_POST ['choice4'])){
choice4();
}
?>
<form method="post" action="output.php">
<input type="submit" name="choice3" id="choice3" value="Choice 3">
<input type="submit" name="choice4" id="choice4" value="Choice 4">
</form>
在Output.php中,
function choice3(){} and function choice4(){}
每个功能都有不同的输出。 但现在,当我点击按钮时,没有任何显示。
感谢您的帮助!!
答案 0 :(得分:0)
只需用此
替换您的代码即可<?php
include 'output.php';
$choice = $_POST['choice'];
if ($choice == 'choice3') {
choice3();
} else if ($choice == 'choice4') {
choice4();
}
?>
<script>
function make_choice(choice) {
document.getElementById('choice').value = choice;
document.choice_form.submit();
}
</script>
<form method="post" action="" name="choice_form">
<input type="hidden" name="choice" id="choice" value="" />
<input type="button" name="choice3" id="choice3" value="choice3" onclick="make_choice(this.value);">
<input type="button" name="choice4" id="choice4" value="choice4" onclick="make_choice(this.value);">
</form>
答案 1 :(得分:0)
将index.html.php和output.php替换为
<强>的index.php 强>
<form method="post" action="output.php">
<input type="submit" name="choice3" id="choice3" value="Choice 3">
<input type="submit" name="choice4" id="choice4" value="Choice 4">
</form>
<强> Output.php 强>
<?php
if (isset ($_POST ['choice3']))
{
/ body of the choice 3 function without the function signature
}
elseif(isset ($_POST ['choice4']))
{
/ body of the choice 4 function without the function signature
}
?>