选择PHP中的选项不能正确回显

时间:2013-08-12 18:03:41

标签: php forms selection

作为前驱,值得一提的是我是PHP新手。我花了大约3个小时研究看起来应该是一个简单的修复。

选择提交后,使用PHP回显表单,我的下拉菜单只回显第一个名称,无论选择哪一个。

这是我的代码:

<form action="echo_form_email.php" method="GET">

<p>
<div id="cheddar">Cashier: <input id="cashier" name="cashier" type="text"></div> 
</p>

<P>
<div id="q">Did the cashier front the register?</div>
<div id="radio1"><input type="checkbox" name="front_register" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="front_register" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="front_register" value="N/A">N/A</div>
</p>

<p>
<div id="q">Genuinely greet customer with eye contact?</div>
<div id="radio1"><input type="checkbox" name="greets" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="greets" value="No">No</div> 
</p>

<p>
<div id="q">Scan/unload B.O.B. (If no bagger)</div>
<div id="radio1"><input type="checkbox" name="scan_bob" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="scan_bob" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="scan_bob" value="N/A">N/A</div>
</p>

<p>
<div id="q">Carry conversation around product in basket or genuine conversation?</div>
<div id="radio1"><input type="checkbox" name="conversation" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="conversation" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="conversation" value="N/A">N/A</div>
</p>

<p>
<div id="q">Offer buddy bucks to parent at beginning of order?</div>
<div id="radio1"><input type="checkbox" name="buddy" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="buddy" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="buddy" value="N/A">N/A</div> 
</p>

<p>
<div id="q">Avoid side conversations?</div>
<div id="radio1"><input type="checkbox" name="side_conversation" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="side_conversation" value="No">No</div> 
</p>

<p>
<div id="q">Point out and circle savings?</div>
<div id="radio1"><input type="checkbox" name="savings" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="savings" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="savings" value="N/A">N/A</div>
</p>

<p>
<div id="q">Offer carryout (if no bagger)?</div>
<div id="radio1"><input type="checkbox" name="carry_out" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="carry_out" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="carry_out" value="N/A">N/A</div>
</p>

<p>
<div id="q">Give a genuine "thank you"?</div>
<div id="radio1"><input type="checkbox" name="thanks" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="thanks" value="No">No</div> 
</p>

<p>
<div id="cheddar">Digital Signature</div>
<div id="cheddar"><input type="tel" name="sign1" placeholder="Peoplesoft ID"></div>
</p>

<p>
<div id="auditingasm">ASM performing audit: <br />
<select name="asm">
<option value="John Doe">John Doe</option>
<option value="Jane Doe">Jane Doe</option>
<option value="Little Doe">Little Doe</option>
<option value="Big Doe">Big Doe</option>
</select>
</p>

<br />
<input type="submit" value="submit" name="submit">
<input id="reset" type="reset">
</form>

使用上面的代码,无论我在提交之前选择哪个选项,回显的结果总会以“John Doe”的形式返回。

这是我的PHP:

<?PHP
if (! empty($_GET['cashier'])){
   echo 'Cashier receiving audit: ' . $_GET['cashier'];
}
echo "<br />";
if (! empty($_GET['asm'])){
   echo 'ASM performing audit: ' . $_GET['asm'];
}
    echo "<br /><Br />";
if (! empty($_GET['front_register'])){
       echo 'Did cashier front the register? ' . $_GET['front_register'];
}
echo "<br />";
if (! empty($_GET['greets'])){
   echo 'Greet customer with eye contact? ' . $_GET['greets'];
}
    echo "<br />";
if (! empty($_GET['scan_bob'])){
echo 'Scan/Unload BOB (if no bagger) ' . $_GET['scan_bob'];
}
echo "<br />";
if (! empty($_GET['conversation'])){
   echo 'Conversation about groceries, or other genuine conversation? ' .             $_GET['conversation'];
}
echo "<br />";
if (! empty($_GET['buddy'])){
   echo 'Offer Buddy bucks to parent at beginning of order? ' . $_GET['buddy'];
}
echo "<br />";
if (! empty($_GET['side_conversation'])){
   echo 'No side conversations? ' . $_GET['side_conversation'];
}
echo "<br />";
if (! empty($_GET['savings'])){
   echo 'Cashier pointed to and circled savings? ' . $_GET['savings'];
}
echo "<br />";
if (! empty($_GET['carry_out'])){
   echo 'Offered carry out (if no bagger) ' . $_GET['carry_out'];
}
echo "<br />";
if (! empty($_GET['thanks'])){
   echo 'Genuine "thank you?" ' . $_GET['thanks'];
}
echo "<br /><Br />";
if (! empty($_GET['sign1'])){
   echo 'Digital Signature: ' . $_GET['sign1'];
}
?>

我提前感谢

1 个答案:

答案 0 :(得分:3)

您的select语句似乎在语法上是正确的。尝试验证表单并检查输出。

<select name="asm" onchange="return validate(this);">
    <option value="">Select Option</option>
    <option value="John Doe">John Doe</option>
    <option value="John Doe">John Doe</option>
    <option value="Jane Doe">Jane Doe</option>
    <option value="Little Doe">Little Doe</option>
    <option value="Big Doe">Big Doe</option>
</select>

<script type="text/javascript">
function validate(obj){
   alert (obj.value);
   return false;
}
</script>

这将提醒您选择的值,而不将表单传递到下一页进行测试。

你忘了关闭select语句的div标签。