Help making button do two actions: send data and open new page

Jul 28, 2009
Reaction score
I have a contact page where I have a form setup to mail me using the mail function. It does everything it is supposed to and gives a little thanks for getting in touch by means of an echo. What I want to do now is instead of echoing the text, I want it to take the person to a completely new thanks.php page. I am a complete newbie and it is amazing that I was able to make sense of other stuff to get this to work. Please help me. It seems so simple, but everything I try doesn't work for me. Thanks. Here is all of the code that I have in the include. Oh this is php and it is in an include. Sorry.

function spamcheck($field)
//filter_var() sanitizes the e-mail
$field=filter_var($field, FILTER_SANITIZE_EMAIL);

//filter_var() validates the e-mail
if(filter_var($field, FILTER_VALIDATE_EMAIL))
return TRUE;
return FALSE;

//Begins by clearing the output variable
$output = '';

//Sets up an array of required names
$required = array('email','name','message');

//Creates an empty array to hold any errors
$errors = array();

//Check to see if the form was submitted
if (isset($_REQUEST['submit'])) {

//Breaks the required array into individual values
foreach ($required as $field) {

//If the required field is empty, adds an error message (key and value) to the error array
if (empty($_REQUEST[$field])) {

$errors[$field] = 'this is required';


//If there are no errors
if (count($errors)<1) {

//Send an email with the form data or otherwise process the form data - currently this does nothing
$to = '(e-mail address removed)';
$subject = 'Message from BandL Contact Form';
$from = 'From: '.$_POST['email'];
$name = 'Name: '.$_POST['name'];
$company = 'Company: '.$_POST['company'];
$email = 'Email: '.$_POST['email'];
$message = 'Message:
'.wordwrap($_POST['message'], 70);

$body = "$name\n$company\n$email\n\n$message";

$break = '<br />';
$newline = "\n";
$message = str_replace($break, $newline, $message);

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

$output.= '<p class="feedback">';
$output.= 'Thank you for getting in touch. We will address this as soon as possible.';
$output.= '</p>';

echo $output;


// If the form has not be submitted, if builds a string to display the form on the page
$output.= '
<form method="post" id="contactform" action="'.$_SERVER['PHP_SELF'].'"><fieldset>';

$fields = array(
'name' => 'text',
'company' => 'text',
'email' => 'text',
'message' => 'textarea'

foreach ($fields as $field => $type) {

$output.= '
<label for="'.$field.'">';
$output.= ucwords($field); //ucwords changes the text to upper-case
if (isset($errors[$field])) {
$output.= ' <strong class="error">is required</strong>';
$output.= '</label>';

switch ($type) {

case 'textarea':
$output.= '
<textarea name="'.$field.'" id="'.$field.'" cols="30" rows="10">';
if (isset($_REQUEST[$field])) {
$output.= htmlspecialchars($_REQUEST[$field]); //htmlspecialchars escapes any potentially harmful markup including < or > or \ or ' or " characters
$output.= '
</textarea><br />';

$output.= '
<input type="text" name="'.$field.'" id="'.$field.'"';
if (isset($_REQUEST[$field])) {
$output.= ' value="'.htmlspecialchars($_REQUEST[$field]).'"';
$output.= ' /><br />';



$output.= '

<input type="submit" name="submit" value="Submit" />
<br />

echo $output;



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question