我不知道如何发布选择选项。该表单为联系人(选项)字段发布空值。我知道 selected_val 不正确,但不知道如何更正。
表单发布正常,但联系人返回一个空值。任何人都可以帮助解决如何更正PHP。
这是PHP
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$selected_val = $_POST['contact']; "You have selected :" .$selected_val;
$message = $_POST['message'];
$from = 'From your website';
$to = 'somedomain.com';
$subject = 'Visitor Inquiry';
$body = "From: $name\n E-Mail: $email\n Phone: $phone\nCity: $city\nContact: $contact\nMessage: $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
// Check if business has been entered
if (!$_POST['company']) {
$errBusiness = 'Please enter your business or organization name';
}
// Check if phone has been entered
if (!$_POST['phone']) {
$errPhone = 'Please enter your phone number';
}
// Check if phone has been entered
if (!$_POST['phone']) {
$errPhone = 'Please enter the name of your city';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You!
We will be in touch soon.</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}
}
?>
HTML
<form class="form-horizontal form-elements" role="form" method="post" action="services-form.php">
<div class="col-md-8 col-md-offset-2">
<label for="contact">Contact preference</label>
<select class="form-control" id="contact" name="contact">
<option>Email</option>
<option>Phone</option>
</select>
</div>
</form>