DS928
asked on
Making Pop Ups
I have code where a div pop ups after a successful email is sent. However, I am failing to get the same effect for when a field isn't filled out. example. Name, Email or messgae. How would I do this?
<?php
error_reporting(E_ALL);
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "ds@schuremediagroup.com";
$email_subject = "SMG Contact";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die(); }
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.'); }
$subject = $_POST['subject'];
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />'; }
$string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) {
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />'; }
if(strlen($error_message) > 0) {
died($error_message); }
$email_message = "Information.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string); }
$email_message .= "Subject: ".clean_string($subject)."\n";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments: ".clean_string($comments)."\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);?>
<div class="popup" "visibility:hidden">
<div class="close_popup" align="right">X</div>
<div align="center">
Request Sent. Thank you!
</div>
</div>
<?php
}
?>
(edited to add jQuery Zone ~Ray)
ASKER
And this....Not working.
<?php
error_reporting(E_ALL);
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "ds@schuremediagroup.com";
$email_subject = "SMG Contact";
function died($error) {
// your error code can go here
echo "<div>";
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
echo "<div>";
}
I added the jQuery Zone to this question because I think you will get a smoother-looking app if you use a modal window for this. Make a Google search for the exact phrase
http://jenniferperrin.com/blog/jquery-tutorial-popup-modal-contact-form/
This looks well thought-out, too:
http://net.tutsplus.com/tutorials/javascript-ajax/progressively-enhance-a-form-link-to-modal-form/
jquery modal window email formand read the first few links. This one is particularly on-point and would provide a good starting point:
http://jenniferperrin.com/blog/jquery-tutorial-popup-modal-contact-form/
This looks well thought-out, too:
http://net.tutsplus.com/tutorials/javascript-ajax/progressively-enhance-a-form-link-to-modal-form/
Do you think you could post the more code? Well, actually it would be better to build a demo on jsfiddle.net and then let us work with it.
ASKER
The two working parts are the PHP at the top of the page. And the form somewhere in the middle. At the bottom of the PHP code you can see the div that works. "Request Sent. Thank You" I want the error code to work the same way. Thak you.
index.php
index.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! You nailed this one right on the head!
ASKER
Open in new window