我有以下代码,我试图让'Finalize Draft Order'提交按钮仅在按下/设置'Create Draft Order'按钮时出现。现在,按下“创建草稿订单”按钮后,按钮不会显示。它只显示我是否从if(isset函数。
)中取出我做错了什么?
<form method="POST" name="form">
<input type="submit" value="Create Draft Order" name="shuffle">
</form>
Shuffled results: <br>
<div class="main-bag">
<div class="shuffle_results" id="results"></div>
<form method="post">
<?php
$count = 0;
foreach ($array as $result) :
$count++;
$shuffle_count = $count;
$shuffle_firstname = htmlentities($result['firstname']);
$shuffle_lastname = htmlentities($result['lastname']);
$shuffle_id = htmlentities($result['id']);
$shuffle_username = htmlentities($result['username']);
$shuffle_email = htmlentities($result['email']);
?>
<input type="hidden" name="count[]" value="<?php echo $shuffle_count; ?>">
<input type="hidden" name="firstname[]" value="<?php echo $shuffle_firstname; ?>">
<input type="hidden" name="lastname[]" value="<?php echo $shuffle_lastname; ?>">
<input type="hidden" name="id[]" value="<?php echo $shuffle_id; ?>">
<input type="hidden" name="username[]" value="<?php echo $shuffle_username; ?>">
<input type="hidden" name="email[]" value="<?php echo $shuffle_email; ?>">
<?php
endforeach;
// only show this button if we have done a shuffle
if ( isset($_POST['shuffle'] ) ) :
echo '<input type="submit" value="Finalize Draft Order" name="insert">';
endif;
?>
更新:
$array = array();
while ($row = mysqli_fetch_assoc($query)) {
$array[] = array(
'id' => $row['id'],
'firstname' => $row['firstname'],
'lastname' => $row['lastname'],
'username' => $row['username'],
'email' => $row['email']
);
if (isset($_POST['shuffle'])) {
}
}
shuffle($array);
echo json_encode($array);
答案 0 :(得分:0)
我认为没有设置$ _POST ['shuffle']。而不是使用提交按钮,它将您的代码更改为:
<form method="POST" name="form">
<input type="hidden" name="shuffle" value="true">
<input type="submit" value="Create Draft Order">
</form>
我很确定提交的名字不计入POST值。
答案 1 :(得分:0)
这是你的问题。您的输入按钮名为shuffle,在提交时不会传递。如果添加一个名为“shuffle”的新隐藏输入元素,它将通过它。
修改强>
在按下创建草稿按钮后,您已在问题中说过了。因此,根据您的例子:
<form method="POST" name="form">
<input type="submit" value="Create Draft Order" name="form">
<input type="hidden" name="shuffle" value="1">
</form>
Shuffled results: <br>
<div class="main-bag">
<div class="shuffle_results" id="results"></div>
<form method="post">
<?php
$count = 0;
foreach ($array as $result) :
$count++;
$shuffle_count = $count;
$shuffle_firstname = htmlentities($result['firstname']);
$shuffle_lastname = htmlentities($result['lastname']);
$shuffle_id = htmlentities($result['id']);
$shuffle_username = htmlentities($result['username']);
$shuffle_email = htmlentities($result['email']);
?>
<input type="hidden" name="count[]" value="<?php echo $shuffle_count; ?>">
<input type="hidden" name="firstname[]" value="<?php echo $shuffle_firstname; ?>">
<input type="hidden" name="lastname[]" value="<?php echo $shuffle_lastname; ?>">
<input type="hidden" name="id[]" value="<?php echo $shuffle_id; ?>">
<input type="hidden" name="username[]" value="<?php echo $shuffle_username; ?>">
<input type="hidden" name="email[]" value="<?php echo $shuffle_email; ?>">
<?php
endforeach;
// only show this button if we have done a shuffle
if ( isset($_POST['shuffle'] ) ) :
echo '<input type="submit" value="Finalize Draft Order" name="insert">';
endif;
?>
答案 2 :(得分:0)
我不知道PHP meame69和ScottyMcGready正在使用什么版本的PHP,但您可以通过检查isset($ _ POST [“submit”])来检查是否单击该按钮是真的。
我还不能评论,但是一旦我弄清楚Becky的代码有什么问题,我会编辑这个。