ここで最初の質問ですので、よろしくお願いします!
修正しようとしている送信フォームは、検証スクリプトを統合した後、機能しなくなりました。メールは送信されませんが、機能しているようです。
HTML:
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript">
/**
* Basic jQuery Validation Form Demo Code
* Copyright Sam Deering 2012
* Licence: http://www.jquery4u.com/license/
*/
(function($,W,D)
{
var JQUERY4U = {};
JQUERY4U.UTIL =
{
setupFormValidation: function()
{
//form validation rules
$("#contactform").validate({
rules: {
firstname: "required",
lastname: "required",
email: {
required: true,
email: true
},
phone: "required",
comment: "required",
},
messages: {
firstname: "Please enter your firstname",
lastname: "Please enter your lastname",
email: "Please enter a valid email address",
phone: "Please enter a valid email phone number",
comment: "Please enter your reason for inquiry"
},
submitHandler: function(form) {
form.submit();
}
});
}
}
//when the dom has loaded setup form validation rules
$(D).ready(function($) {
JQUERY4U.UTIL.setupFormValidation();
});
})(jQuery, window, document);
</script>
フォーム:
<form action="send_form_email.php" method="post" id="contactform">
<div id="form-content">
<fieldset>
<div class="fieldgroup">
<label for="firstname">First Name*</label>
<input type="text" name="firstname">
</div>
<div class="fieldgroup">
<label for="lastname">Last Name*</label>
<input type="text" name="lastname">
</div>
<div class="fieldgroup">
<label for="email">Email*</label>
<input type="text" name="email">
</div>
<div class="fieldgroup">
<label for="phone">Phone*</label>
<input type="text" name="phone">
</div>
<div class="fieldgroup">
<label for="comment">Reason for Inquiry*</label>
<textarea name="comment"></textarea>
</div>
<div class="fieldgroup">
<input type="submit" value="Sumbit">
</div>
</fieldset>
</div>
</form>
send_form_email.php:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "donliggett@gmail.com";
$email_subject = "Web Submission";
$first_name = $_POST['firstname']; // required
$last_name = $_POST['lastname']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$reason = $_POST['comment']; // 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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Reason for Inquiry: ".clean_string($reason)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
StackOverflowの大ファン、みんなとギャルに感謝します!