Jump to content

header help


toolman

Recommended Posts

Hi there,

 

I have a form which displays a "successful" message if the form is completed correctly. However, I want the form to go to another url if it is successful. I have tried this, but I get the "headers already sent..." message

 

// Add New Subscriber Success Message
$successMsg = header('Location: http://www.example.com/');

 

is there another way to forward onto another page?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/211912-header-help/
Share on other sites

Thanks for the reply.

 

Can anyone reccommend a way of forwarding the user to another page if the form is successful?

 

This is my code:

 

<?php if(isset($_GET['message']) && $_GET['message'] == 2):
			echo $successMsg;
	  elseif(isset($_GET['message']) && $_GET['message'] == 1):
	  		echo $errorMsg;
	  elseif(isset($_GET['message']) && $_GET['message'] == 4):
	  		echo $unsubscribeMsg;
	  elseif(isset($_GET['message']) && $_GET['message'] == 5):
	  		echo $failUnsubscribeMsg;
	  else:
?>

 

and

 

// Add New Subscriber Success Message
$successMsg = "<font color='green'>You have been successfully subscribed from the mailing list</font>";

Link to comment
https://forums.phpfreaks.com/topic/211912-header-help/#findComment-1104522
Share on other sites

I am not sure what you mean if the form is succes, but you could check if the submit button is pressed and a certain form value is not empty. like this. I am using method post btw.

Place this before the <html> tag

 

<?php
$flag = false; // if flag is false show form.

if(isset($_POST['submit'])){//so if submit is pressed
    if ($message !== ' '){// message is not empty, you could add any additional if here btw. Just dont know how you form looks like
    echo "header('Location: http://www.example.com/')";
    $flag = true;// if flag is true dont show the form
}else{
    $flag = false;//if flag is false show it.
}
// dont forget to put  $flag in front of form
if ($flag=false){
echo 'put your form in here';
}

?>

 

Hope this is what your looking for.

ciao!

Link to comment
https://forums.phpfreaks.com/topic/211912-header-help/#findComment-1104597
Share on other sites

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.