1

作为先驱,值得一提的是我是 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'];
}
?>

提前致谢

4

1 回答 1

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 标记。

于 2013-08-12T18:58:54.597 回答