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 Quote Link to comment 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(). Quote Link to comment 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>"; Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.