Link to home
Start Free TrialLog in
Avatar of DS928
DS928Flag for United States of America

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
                                         }
										 ?>

Open in new window

(edited to add jQuery Zone ~Ray)
Avatar of DS928
DS928
Flag of United States of America image

ASKER

I tried this but 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
     <div class="popup" "visibility:hidden">
     <div class="close_popup" align="right">X</div>
     	<div align="center">
	 "We are very sorry, but there were error(s) found with the form you submitted. ";
	 	</div>
	 </div>
	 echo "These errors appear below.<br /><br />";
	 echo $error."<br /><br />";
	 echo "Please go back and fix these errors.<br /><br />";
	 die();    }

Open in new window

Avatar of DS928

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>";
	 }

Open in new window

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
jquery modal window email form
and 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/
Avatar of Eddie Shipman
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.
Avatar of DS928

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
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DS928

ASKER

Thank you!  You nailed this one right on the head!