Page 1 of 1

Redirecting page

Posted: Mon Oct 29, 2007 9:26 am
by westen
I have an html form that a user fills in. When the user submits the form the input is checked and if there there are any errors they are displayed. This works fine. If there are not any errors I wish to redirect to another page. The only function I can find for redirecting is header() but I do not understand how it works. It says I am not allowed to display anything before calling it but I clearly have to display my form before redirecting to another page. Can someone please explain to me how this works, I would appreciate any help.

Apologies if this is a repost, I attempted to post this question on friday but I lost my net connection and I cannot find the thread so I think it did not post properly.

Cheers,
westen.

Form Action

Posted: Mon Oct 29, 2007 9:51 am
by N1gel
You don't want to use the header for submitting a form.

You want to set the action of the form to the page where you are going to process the form. like

Code: Select all

<FORM action="http://somesite.com/prog/adduser" method="post">
you could try looking @

w3 on forms

or just search google for 'form action' or 'form post'

its prety simple you just set the action of the form to be the page you want to send them to

Posted: Mon Oct 29, 2007 10:18 am
by westen
Yes I submit the form and check the input using the same php file, if the input is without errors I then want to redirect to another page, if it has errors the same page is displayed with the errors written at the top. The form submission and error checking works I just do not know how to redirect.

Posted: Mon Oct 29, 2007 10:47 am
by shiznatix

Code: Select all

header('Location: http://yourdomain.com/the_page_for_no_errors.php');
die();//don't forget to die after you send the header!
that will do the trick

Posted: Mon Oct 29, 2007 10:54 am
by westen
Thanks, but thiat is what I already had.
I get the following error message:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/ulondoco/public_html/header.php:5) in /home/ulondoco/public_html/register.php on line 198
Cheers guys.

Posted: Mon Oct 29, 2007 11:02 am
by feyd
That particular error is posted about a LOT. Please search for the solution.

Posted: Mon Oct 29, 2007 11:30 am
by westen
Apologies and thanks. I am sorted now, I followed someones advice to call ob_start() and ob_end_flush(), I have no idea what this does but it works!

Cheers,
Westen

Posted: Mon Oct 29, 2007 11:53 am
by feyd
Unfortunately, anyone who suggests using output buffering as a solution is generally delusional. i.e. It is not a solution. It's a work-around that could easily be avoided if the code was written such that all page logic happens before any output starts.

Posted: Mon Oct 29, 2007 12:29 pm
by westen
Really? I was not aware that it was bad form to mix in the output with the logic, so you save everything during the logic stage in variables and then ouput it all at the end?

Posted: Mon Oct 29, 2007 12:35 pm
by feyd
Separating business/program logic from presentation logic is the logical conclusion when one wishes to keep both fairly easy to maintain. This is especially true in environments where the programmer doesn't create the page designs (and pages.)