At 3/10/2007 11:47 AM, Don Don wrote:
Hi all, i am building a system using php and am trying to separate
the html codes from the php codes (i.e. placing them in separate
files), I am from the java struts/spring background and seem to be
finding it difficult doing that at the moment with php.
I've got a registration form in html with the action pointing to
a separate php file that will process the form when
submitted. when i want to output errors or messages, its currently
being outputed in the resulting code generated by the php
file. What i would like is to return to the html page and display
the messages there.
You can establish the HTML form as a template which your PHP script
reads, modifies, and downloads to the browser. For example, you
could have a structure like this in a template:
<p class="error">@error@</p>
<form action="?" type="post" ...>
...
</form>
Read the template with file_get_contents(), use str_replace() to
replace '@error@' with your current error message (or an empty
string), and echo the template to the browser.
As others have said, one easy model for form processing is for the
form to post to itself. Here's how such a script might work:
___________________________
initialize
if we are receiving a posted form
{
validate posted input
if no error
{
act on posted input
end
}
plug error message into form
}
display form
___________________________
If the user submits the form, the logic begins again.
Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php