我创建了一个使用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表单提交者正在工作)
我知道如何解决这个问题吗?
答案 0 :(得分:4)
将type =“button”更改为type =“submit”
写
<input class="button" name="submit" type="submit" value="submit" onClick="javascript:$('#contactform').parsley( 'validate' );" />
而不是
<input class="button" name="submit" type="button" value="submit" onClick="javascript:$('#contactform').parsley( 'validate' );" />