Jump to content

form thank you on same page


kayz100

Recommended Posts

Hi guys, my form works fine but I want the thank you message on the same page in red font, At the moment I am redirecting to thanks.htm and my form is on contme.php,

how do i do that?

script below:

<?php 
$Email_address ='sam@yahoo.com ';
session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['submit']))
{
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$user_message = $_POST['message'];


if(empty($name)||empty($visitor_email))
{
$errors .= "\n Name and Email are required fields. "; 
}
if(IsInjected($visitor_email))
{
$errors .= "\n Bad email value!";
}
if(empty($_SESSION['6_letters_code'] ) ||
 strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
$errors .= "\n The captcha code does not match!";
}
if(empty($errors))
{
$to = $Email_address;
$subject="loverman";
$from = $Email_address;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';


$body = "$name contacted you by submitting the message below:\n\n".
"Name: $name\n\n".
"Email: $visitor_email \n\n".
"Message: \n\n ".
"$user_message\n\n".
"IP: $ip\n"; 


$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";


mail($to, $subject, $body,$headers);


//header('Location: ?success');
//echo "your enquiry was submitted successfully, thank you,";
header('Location: contme.php');
echo "Form submitted succesfully, thank you";
} else { 
echo "Form failed to send";
}
}


function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/284632-form-thank-you-on-same-page/
Share on other sites

The portion of your code below: 

//header('Location: ?success');
//echo "your enquiry was submitted successfully, thank you,";
header('Location: contme.php');
echo "Form submitted succesfully, thank you";
} else { 
echo "Form failed to send";
}
}

Change To:

//header('Location: ?success');
//echo "your enquiry was submitted successfully, thank you,";
header('Location: thanks.htm');
} else { 
echo "Form failed to send";
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.