1 reply [Last post]
suavedesign's picture
Last seen: 5 years 42 weeks ago
Timezone: GMT-5
Joined: 2010-12-01
Posts: 128
Points: 191

I have a contact form on my site. Once the user presses "submit", he is redirected to a page with a message. I want, instead for the user to stay on that contact page on my website, and have the message appear right there on the page. How do I do that? I dont know javascript/php, I copied the code fot the form from a tutorial.
The url to my site is: http://rejuvenateusa.org/contactr.html

this is the code:

//Don't want to get your hands dirty? We've placed all variables in a convenient place for you to modify.
$recipientEmail = "[email protected]"; // enter recipient email address. Don't delete the double quotation marks
$emailSubject = "Message from contact form";
$successMessage = "Thanks for your message! We'll be in contact shortly.";
$error  = ""; //leave blank
    $name   = $_POST['name'];
    $email   = $_POST['email'];
    $message   = $_POST['message'];
	$result = checkForSpam(Array($name));
	if(trim($name) == "" || trim($email) == "" || trim($message) == ""){
    $error = "Oops! All fields are required.";
	else if($result){
		$error = 'You have entered invalid characters.';
	else if(!validEmail($email)){
		$error = '*Your email address is not valid';
		$email = '';
	if($error == ''){
	$priority = 3;
	$php_version = phpversion();
	$headers = "From: $name <$email>\n";
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
	$headers .= "X-Priority: $priority\n";
	$headers .= "X-Mailer: PHP $php_version\n";
	$subject = $emailSubject;
	$to_email = $recipientEmail;
	mail($to_email, $subject, $message, $headers);
echo $successMessage;
if(!isset($_POST['submit']) || $error != '')
echo $error;
<form method="post" action="contact.php">
<input type="text" name="name" value="<?php echo $name; ?>">
<input type="text" name="email" value="<?php echo $email; ?>">
<textarea name="message"><?php echo $message; ?></textarea>
<input type="submit" name="submit" value="submit">
//utility functions
function validEmail($email)
function checkForSpam($fields){
    $spam = false;
    for ($i=0;$i<count($fields);$i++){
        if (eregi("%0A",$fields[$i]) || eregi("%0D",$fields[$i]) || eregi("\r",$fields[$i]) || eregi("\n",$fields[$i])){
            $spam = true;
    return $spam;

thanks in advance

Tony's picture
Last seen: 5 weeks 5 days ago
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5343
Points: 2964

Hi suavedesign, This is a PHP

Hi suavedesign,
This is a PHP question.
You will need to change you contact form page from html to PHP.
and have the form submit to itself something like:

<form method="post"  action="<?php $_SERVER['PHP_SELF'];?>" >