Code: Select all
<form method="post" action="send_email.php">
<div id="contact_form">
<div align="left" class="green18">Contact Us</div> <br/> <br/>
<label>Your Name:</label> <input class="texta" name ="name" size="20" maxlength="49"/> <br/> <br/>
<div class ="error" style="position:relative;bottom:40px;left:128px" >
<?php //Retrieve the encoded errors string from send_email.php page
$errors_string=$_GET['errors_string'];
//Explode the decoded errors string back to an array.
$errors = explode(",", $errors_string);
echo $errors[0];?>
</div>
<label>Your Company Name:</label> <input class="texta" name ="company" size="30" maxlength="66"/> <br/> <br/>
<div class ="error" style="position:relative;bottom:40px;left:128px" >
<?php //Retrieve the encoded errors string from send_email.php page
$errors_string=$_GET['errors_string'];
//Explode the decoded errors string back to an array.
$errors = explode(",", $errors_string);
echo $errors[1];?>
</div>
<label>Subject(Optional):</label> <input class="texta" name ="subject" size="20" maxlength="49"/> <br/> <br/>
<label>Email:</label> <input class="texta" name ="email" size="20" maxlength="49"/> <br/> <br/>
<div class ="error" style="position:relative;bottom:40px;left:128px" >
<?php //Retrieve the encoded errors string from send_email.php page
$errors_string=$_GET['errors_string'];
//Explode the decoded errors string back to an array.
$errors = explode(",", $errors_string);
echo $errors[2];?>
</div>
<label>Message:</label> <textarea style="float:left" class="" name ="message" cols="40" rows="3"> </textarea> <br/> <br/>
<div class ="error" style="position:relative;bottom:-19px;left:-260px" >
<?php //Retrieve the encoded errors string from send_email.php page
$errors_string=$_GET['errors_string'];
//Explode the decoded errors string back to an array.
$errors = explode(",", $errors_string);
echo $errors[3];?>
</div>
<button class="button" type ="submit" name ="submit">Submit</button> <br/>
<div id ="sent" >
<?php //Retrieve the user id from send_email.php page
$sent=$_GET['sent'];
$send_msg = urldecode($sent); echo $send_msg; ?>
</div> <!--closes sent-->
</div>
</form>
Code: Select all
<?php
//address error handling
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
if (isset($_POST['submit'])) {
$errors = array();
// Connect to the database.
require('config/config.php');
//Check for errors.
//Check to make sure they entered their name and it's of the right format.
if (eregi ("^([[:alpha:]]|-|')+$", $_POST['name'])) {
$a = TRUE;
} else {
$a = FALSE;
$errors[0] = '*Please enter a valid name.';
}
//Check to make sure they entered their company name.
if (!empty ( $_POST['company'])) {
$b = TRUE;
} else {
$b = FALSE;
$errors[1] = '*Please enter company name.';
}
//Check to make sure email is valid.
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) {
$c = TRUE;
}else {
$c = FALSE;
$errors[2] = '*Please enter a valid email address.';
}
//Check to make sure they entered their message.
if (!empty ( $_POST['message'])) {
$d = TRUE;
} else {
$d = FALSE;
$errors[3] = '*Please enter your message.';
}
//If no errors
if (empty($errors)) {
//Create variables for all the post .
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$message = $_POST['message'];
$ip = $_SERVER[REMOTE_ADDR];
$date = (date("Y/m/d:G:i:s"));
$timestamp = ( mktime(date(H), date(i), date(s), date(m) , date(d) , date(Y)));
//Formulate the insert query.
$query = "INSERT INTO emails ( email_id, name, company, email, message, ip, date,timestamp) VALUES ( 0, '$name','$company','email', '$message', '$ip' , '$date', '$timestamp' )";
$result = mysql_query($query) or die("Data could not be inserted into table because: " .mysql_error());
if (mysql_affected_rows() == 1) {
// Display success message
$sent_msg = "Your email has been sent. We will get back to you shortly.";
$sent = urlencode($sent_msg);
// Display contact page
header("Location: contact_page.php?sent=$sent"); exit();
}else{die("There was a problem: " . mysql_error());}
//Display error messages.
} else {// if errors array is not empty
//Confer the errors array into a string
$errors_string = implode(",", $errors);
//Encode the imploded string.
$error_message = urlencode($errors_string);
// Display page
header("Location: contact_page.php?errors_string=$errors_string"); exit();
}//End of if there are errors.
}//End of if submit.
?>
Also, another problem I just noticed is that, the errors[3] variable isn't getting passed back to the form page. I don't know if it's because the url can only pass so much info to a second page. The page in question can be located here:
http://creativewizz.com/contact_page.php