您好我试图从选择选项中获取值但发送的值始终为1我不知道为什么这里是代码:
<form id="landingform" method="POST" action="form/process.php">
<input id="nme" name="name" type="text" placeholder="Name" />
<input id="mail" name="email" type="email" placeholder="Email" />
<input name="address" type="text" placeholder="Address" />
<select name="state">
<option value="Alabama" selected="selected">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="California">California </option>
<option value="Colorado">Colorado</option>
<option value="Connecticut">Connecticut </option>
<option value="Delaware">Delaware</option>
<option value="Florida">Florida</option>
<option value="Georgia">Georgia</option>
<option value="Hawaii">Hawaii</option>
<option value="Idaho">Idaho</option>
<option value="Illinois">Illinois</option>
<option value="Indiana">Indiana</option>
<option value="Iowa">Iowa</option>
<option value="Kansas">Kansas</option>
<option value="Kentucky">Kentucky</option>
<option value="Louisiana">Louisiana</option>
<option value="Maine">Maine</option>
<option value="Maryland">Maryland</option>
<option value="Massachusetts">Massachusetts</option>
<option value="Michigan">Michigan</option>
<option value="Minnesota">Minnesota</option>
<option value="Mississippi">Mississippi</option>
<option value="Missouri">Missouri</option>
<option value="Montana">Montana</option>
<option value="Nebraska">Nebraska</option>
<option value="Nevada">Nevada</option>
<option value="New Hampshire">New Hampshire</option>
<option value="New Jersey">New Jersey</option>
<option value="New Mexico">New Mexico</option>
<option value="New York">New York</option>
<option value="North Carolina">North Carolina</option>
<option value="North Dakota">North Dakota</option>
<option value="Ohio">Ohio</option>
<option value="Oklahoma">Oklahoma</option>
<option value="Oregon">Oregon</option>
<option value="Pennsylvania">Pennsylvania</option>
<option value="Rhode Island">Rhode Island</option>
<option value="South Carolina">South Carolina</option>
<option value="South Dakota">South Dakota</option>
<option value="Tennessee">Tennessee</option>
<option value="Texas">Texas</option>
<option value="Utah">Utah</option>
<option value="Vermont">Vermont</option>
<option value="Virginia">Virginia</option>
<option value="Washington">Washington</option>
<option value="West Virginia">West Virginia</option>
<option value="Wisconsin">Wisconsin</option>
<option value="Wyoming">Wyoming</option>
</select>
<input name="zipcode" type="text" placeholder="Zipcode" />
<input id="msg" name="coment" type="text" placeholder="Comments..." style="height:50px;"/>
<input class="submit" type="submit" value="" onclick="return validateForm()"/>
</form>
process.php:
$name = $_POST["name"];
$email = $_POST["email"];
$address = $_POST["address"];
$zipcode = $_POST["zipcode"];
$state = isset($_POST["state"]);
$coment = $_POST["coment"];
/* This takes the information and lines it up the way you want it to be sent in the email. */
$subject = ' Contact From '.$name; // Subject for the email
$body = "Name: $name <br />";
$body .= "Email: $email <br />";
$body .= "Address: $address <br />";
$body .= "State: $state <br />";
$body .= "Zipcode: $zipcode <br />";
$body .= "Msg: $coment <br />";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "<br />";
$sucess = mail($site_owners_email, $subject, $body, $headers);
$url = '../thank-you.html';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
我得到的所有其他值都很好,但状态始终是邮件中的值1为什么是这个?就像一个布尔值?感谢
答案 0 :(得分:5)
$state = isset($_POST["state"]);
将返回一个布尔值。这就是你获得1的原因。
你应该这样做:
$state = $_POST["state"];
答案 1 :(得分:1)
这是因为你有
$state = isset($_POST["state"]);
将其更改为
$state = $_POST["state"];
第一个是返回一个布尔值,因为它会检查该变量是否已设置。
答案 2 :(得分:0)
在状态中你放置了isset($ _ POST [&#34; state&#34;]) 这是一个布尔值 你看到的1意味着真实 你必须写:
$state = $_POST["state"];