我使用materialize框架创建了一个简单的联系表单,并且只要我检查发布的值为空,选择元素就不会在表单提交原因上发布数据。您有任何想法如何处理这个问题?感谢
这是我的表单代码:
<form class="col s12 m12 l12" id="contact-form" method="post" action="php/send_form_email.php">
<div class="row">
<div class="input-field col s12 m6 l6">
<input id="icon_prefix" type="text" name="first_name" class="validate" required>
<label for="icon_prefix">Name</label>
</div>
<div class="input-field col s12 m6 l6">
<input id="email" type="email" class="validate" name="email" required>
<label for="email">Email address</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m12 l12">
<select name="traffic" required>
<option value="" selected disabled>Choose your option</option>
<option value="youtube">YouTube</option>
<option value="facebook">Facebook</option>
<option value="google search">Google search</option>
</select>
<label>How did you know about us?</label>
</div>
</div>
<button id="submit-btn" class="waves-effect waves-light btn z-depth-0" type="submit" value="Submit">submit</button>
<button id="reset-btn" class="waves-effect waves-light btn z-depth-0" type="reset">reset</button>
</form>
这是我的send_form_email.php:
<?php
if(isset($_POST['email'])) {
$email_to = "info@abcd.com";
$email_subject = "Request";
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$traffic = $_POST['traffic']; // required
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Traffic source: ".$traffic."\n";
// create email headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
答案 0 :(得分:0)
它实现了错误Materialize Issue。如果您可以使用Jquery或JS,您现在可以通过添加隐藏输入并更改其值来解决它。
<input type="hidden" name="select_name">
<select id="select_input">
<option value="" disabled selected>Choose opt</option>
<option value="value1">Value 1</option>
</select>
<script>
$("#select_input").on('change', function () {
$("input[value='select_name']").val($(this).val());
})
</script>
或者您可以使用class="browser-default"
,但也有问题Browser default Issue