Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   Internet Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=25)
-   -   HTML FORMS and PHP (https://www.cableforum.uk/board/showthread.php?t=37058)

Tricky 22-10-2005 23:30

HTML FORMS and PHP
 
I have a webpage mypage.htm that has a form which has it's action as "mypage.htm" I.e. Reloads itself with some posted values

I have some embedded PHP which check the fields are valid (email address, not blank etc) and if they are not shows an error against the invalid entries

An internal field "$allvalid" is 0 when all is ok and > 0 when errors are present

I want to redirect "mypage.htm" to some other page I.e. "success.htm" if $valid=0, I've tried the "Header: Location ..." but this won't work because I am already outputting data to screen

Any ideas? :confused:

Strzelecki 22-10-2005 23:58

Re: HTML FORMS and PHP
 
Best way is to use Javascript afterward, but you can work around in PHP like this:
PHP Code:

<?php
ob_start
();

// script with screen output

ob_end();
?>


BBKing 23-10-2005 09:31

Re: HTML FORMS and PHP
 
Quote:

Any ideas?
Just done something similar - redirected to the same page with different parameters if a particular parameter was set. I use JSPs though, but the principle should be fairly similar - they don't allow you to redirect after you've done any output at all, so you must make your decision first, before outputting anything. This means using a separate pure PHP page as the target. Then, if you find all's well, redirect to success.htm, otherwise redirect to mypage.htm.

You could rewrite mypage.htm as php, but I don't totally approve of mixing content and programmatical data in the same file. Easier to debug if you keep it separate.

Tricky 23-10-2005 20:40

Re: HTML FORMS and PHP
 
Sorted it, just do all the error checking and redirection before starting any output! (doh!)
I am too old for this stuff

BBKing 23-10-2005 22:56

Re: HTML FORMS and PHP
 
That's the key - remember that once you start printing to browser, you can't stop. Like Pringles.

OK, that's the Guinness talking...


All times are GMT. The time now is 12:35.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum