我有一个简单的html表单,使用PHP将信息发送到我的邮件。
当我使用Chrome时,所有参数都会正确发送,但是当我尝试使用Firefox发送表单时,select标签中的值不会发送到我的邮箱。如果我用LiveHeaders检查标题,我可以看到该参数不在标题中。
形式:
<form method="POST" action="mail.php" id="signup">
<input class="ime1" name="ime1" placeholder="Oseba 1: Ime in Priimek" type="text">
<input class="starost1" name="starost1" placeholder="Starost" type="text"><br/>
<b>City</b>
<select id="problem" name="problem">
<option id="" value="1">London</option>
<option id="" value="2">Ljubljana</option>
<option id="" value="3">Belgrade</option>
<option id="" value="4">Havana</option>
</select>
</form>
PHP代码,mail.php:
<?php
$name1 = $_POST['ime1'];
$starost1 = $_POST['starost1'];
$problem= isset($_POST['problem']) ? $_POST['problem'] : null;
$formcontent=
"REZERVACIJA \n\n"
. "1. OSEBA: $name1 \n"
. " $starost1 let \n "
. " $problem \n ";
$recipient = "cyc@gmail.com";
$subject = "Rezervacija";
$mailheader = "From: asd@sf.com \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
总结:提交表单时,Mozilla没有在标题中发送select(name =“problem”)。
答案 0 :(得分:1)
你的三元运算符是不正确的,它应该用括号括起来以避免混淆
所以它应该是这样的:
(isset($_POST['problem']) ? $_POST['problem'] : '')
或
(isset($_POST['problem'])) ? $_POST['problem'] : ''
答案 1 :(得分:0)
尝试以下
<form method="POST" action="mail.php" id="signup">
<input class="ime1" name="ime1" placeholder="Oseba 1: Ime in Priimek" type="text">
<input class="starost1" name="starost1" placeholder="Starost" type="text"><br/>
<b>City</b>
<select id="problem" name="problem">
<option id="a" value="London">London</option>
<option id="b" value="Ljubljana">Ljubljana</option>
<option id="c" value="Belgrade">Belgrade</option>
<option id="d" value="Havana">Havana</option>
</select>
</form>
PHP代码