toolman Posted August 27, 2010 Share Posted August 27, 2010 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 More sharing options...
Pikachu2000 Posted August 27, 2010 Share Posted August 27, 2010 You can't output anything at all to the browser, not even white space, before using header(). Link to comment https://forums.phpfreaks.com/topic/211912-header-help/#findComment-1104489 Share on other sites More sharing options...
toolman Posted August 28, 2010 Author Share Posted August 28, 2010 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 More sharing options...
Pikachu2000 Posted August 28, 2010 Share Posted August 28, 2010 Can you post more of the code? There's probably a way to do it with header(), but can't say for sure without seeing it. Link to comment https://forums.phpfreaks.com/topic/211912-header-help/#findComment-1104550 Share on other sites More sharing options...
fortnox007 Posted August 28, 2010 Share Posted August 28, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.