Hi all
New here.
I have a basic email form that takes name phone email etc, also has 3 file upload boxes for photos.
I have taken most of the code from free examples off the net and patched it together.
It had an error message if something went wrong. I wanted to put an html page instead of just the txt. So read that I could end tag the php then do html then begin tag the php again. Problem is some of the error message was from a different part of the php code. How can i get this displayed on the html.
Code below:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "email@email.com";
$email_subject = "JoinUs Model Form";
function died($error) {
// your error code can go here
?>
<title>title</title>
<style type="text/css">
body {
background-color: #000;
text-align: center;
}
body,td,th {
color: #FFF;
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
}
</style>
</head>
<body link="#FFFFFF" onload="setTimeout('history.back()',10000)">
<p><img src="../images/logo.png" width="326" height="144" alt="sdadfsd" longdesc="http://www.dgfsfdg.com" /><br />
</p>
<br />
<p>We are very sorry, but there were error(s) found with the form you submitted.</p>
<p>These errors appear below.</p>
####### this is where i want the below errors to appear in same format as html #########
<p>Click back to fix your error(s) or you will be taken back to the form automatically in 10 seconds...</p>
<h6> </h6>
<h6>© asafdsodf 2012</h6>
</body>
</html>
<?php
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
// Where the file is going to be placed
$target_path = "uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['form2']['photo1']);
$target_path = $target_path . basename( $_FILES['form2']['photo2']);
$target_path = $target_path . basename( $_FILES['form2']['photo3']);
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$age = $_POST['age'];
$city = $_POST['city'];
$state = $_POST['state'];
$height_feet = $_POST['height_feet'];
$height_inches = $_POST['height_inches'];
$photo1 = $_FILES['form2']['photo1'];
$photo2 = $_FILES['form2']['photo2'];
$photo3 = $_FILES['form2']['photo3'];
$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,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
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 = "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 .= "Age: ".clean_string($age)."\n";
$email_message .= "Height: ".clean_string($height_feet) .clean_string($height_inches)."\n";
$email_message .= "City: ".clean_string($city)."\n";
$email_message .= "State: ".clean_string($state)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$email_message .= "".clean_string($comments)."\n";
$email_message .= "Comments: ".clean_string($comments)."\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);
?>
<!-- include your own success html here -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>asdf </title>
<style type="text/css">
body {
background-color: #000;
text-align: center;
}
body,td,th {
color: #FFF;
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
}
</style>
</head>
<body link="#FFFFFF">
<p><img src="./images/logo.png" width="326" height="144" alt="asdfahjdsfka" longdesc="http://www.kasdfhdskaha.com" /><br />
</p>
<p>Thank your for applying to adskfha asdfasd. We will be in touch with you very soon.</p>
<p>You will be redirected back to the site in 3 seconds...</p>
<h6> </h6>
<h6>© 2012</h6>
</body>
</html>
<?php
}
?>
Thanks
wolfsta