我创建了一个使用 Parsley.js 验证然后使用 php 提交的表单。表单验证得很好,但它没有提交到 php 页面:form_submission.php
演示表格可以在这里找到http://tanujd.com/demop/contact-form.html(我已经用虚拟内容预先填充了表格以便更容易测试)
使用的 HTML 是:
<form action="form_submission.php" id="contactform" method="post" data-validate="parsley">
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr class="name">
<td>
<label for="firstname">First Name*:</label>
<input type="text" id="firstname" name="firstname" data-trigger="change" required data-required="true" value="dummyfname" />
</td>
<td style="margin-left:10px;">
<label for="lastname">Last Name*:</label>
<input type="text" id="lastname" name="lastname" data-trigger="change" required data-required="true" value="dummylname" />
</td>
</tr>
<tr>
<td>
<label for="mobile">Mobile*</label>
<input type="text" id="mobile" name="mobile" data-type="phone" data-trigger="change" required data-required="true" value="+1123456789" />
</td>
</tr>
<tr>
<td>
<label for="email">Email* :</label>
<input type="text" id="email" name="email" data-type="email" data-trigger="change" required data-required="true" value="dummy@emailid.com" />
</td>
</tr>
<tr>
<td>
<label for="subject">Whats this about*:</label>
<select id="subject" name="subject" required="required" data-required="true">
<option value="1" selected="selected">Yey</option>
<option value="2">Yey1</option>
<option value="3">Yey2</option>
</select>
</td>
</tr>
<tr>
<tr>
<td>
<label for="category">Subject:</label>
<input type="text" id="category" name="category" value="Dummy Subject" />
</td>
</tr>
<tr>
<td>
<label for="message">Tell us about it*</label>
<textarea id="message" name="message" data-trigger="change" required data-required="true">Dummy Text</textarea>
</td>
</tr>
<tr>
<td>
<input type="hidden" id="formid" name="formid" value="contactusform" />
<input class="button" name="submit" type="button" value="submit" onClick="javascript:$('#contactform').parsley( 'validate' );" />
</td>
</tr>
</table>
</form>
页面中的PHP代码:form_submission.php (网上的文件显然有我正确的电子邮件地址)
<?php
$formid = $_POST['formid'];
$email_to = "myemailaddress@goeshere.com";
$first_name = $_POST['firstname']; // required
$last_name = $_POST['lastname']; // required
$mobilenum = $_POST['mobile'];
$email_from = $_POST['email']; // required
$email_subject = "Website Contact Form Submission: ". $_POST['subject'];
$subject = $_POST['subject'];
//$categoryselect = $_POST('category').value();
$message = $_POST['message']; // required
echo($email_from);
$email_message = "Submission details below.\n\n";
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Mobile: ".clean_string($telephone)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Whats this about: ".clean_string($subject)."\n";
$email_message .= "Category: ".clean_string($category)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$email_message = wordwrap($email_message, 70, "\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) or die("Error!");
echo "Thank you for contacting us. We will be in touch with you very soon. \r\n";
?>
该页面验证正常,但它只是没有转到 PHP 页面并提交表单。如果我按原样加载 php 页面,它会通过电子邮件向我发送一条空白消息(所以基本上 php 表单提交者正在工作)
知道如何解决这个问题吗?