我想在提交联系表单后显示svg图像和文本,但我没有任何php经验,所以你们可以帮助解决这个问题。现在提交表单后,它只是显示"您的消息已成功发送"单击提交按钮后。
请参阅我要显示的附件图像Image link
<form id="contact-form" action="formProcess.php">
<ul class="contact-inputs">
<li><input type="text" name="your_name" id="name" placeholder="Name"></li>
<li><input type="email" name="email" id="email" placeholder="Email"></li>
<li><input type="text" name="subject" id="subject" placeholder="Subject"></li>
<li><textarea name="message" id="message" cols="30" rows="5" placeholder="Message"></textarea></li>
<li class="send-btn"><button type="submit" id="submit">Send</button></li>
</ul>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click(function(e){
e.preventDefault();
var name = $("#name").val();
var email = $("#email").val();
var subject = $("#subject").val();
var message = $("#message").val();
$.ajax({
type: "POST",
url: "formProcess.php",
dataType: "json",
data: {name:name, email:email, subject:subject, message:message},
success : function(data){
if (data.code == "200"){
//alert("Success: " +data.msg);
$(".display-error").html(data.msg);
$(".display-error").css("display","block");
$("#contact-form").css("display","none");
} else {
$(".display-error").html("<ul>"+data.msg+"</ul>");
$(".display-error").css("display","block");
}
}
});
});
});
</script>
<?php
$errorMSG = "";
/* NAME */
if (empty($_POST["name"])) {
$errorMSG = "<li>Name is required</li>";
} else {
$name = $_POST["name"];
}
/* EMAIL */
if (empty($_POST["email"])) {
$errorMSG .= "<li>Email is required</li>";
} else if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
$errorMSG .= "<li>Invalid email format</li>";
}else {
$email = $_POST["email"];
}
/* SUBJECT */
if (empty($_POST["subject"])) {
$errorMSG .= "<li>Subject is required</li>";
} else {
$subject = $_POST["subject"];
}
/* MESSAGE */
if (empty($_POST["message"])) {
$errorMSG .= "<li>Message is required</li>";
} else {
$message = $_POST["message"];
}
if(empty($errorMSG)) {
// Set the recipient email address.
// FIXME: Update this to your desired email address.
$recipient = "umerzamanlive@gmail.com";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Subject: $subject\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
(mail($recipient, $subject, $email_content, $email_headers));
$success .= "Your message has been sent successfully";
echo json_encode(['code'=>200, 'msg'=>$success]);
exit;
}
echo json_encode(['code'=>404, 'msg'=>$errorMSG]);