Re: Validating form input data
- From: "stathis gotsis" <stathisgotsis@xxxxxxxxxxx>
- Date: Sun, 30 Apr 2006 17:25:45 +0300
"David Haynes" <david.haynes2@xxxxxxxxxxxx> wrote in message
news:Mp25g.739$jE6.350@xxxxxxxxxxxxxxxxxxxxxxxx
stathis gotsis wrote:that
Hello everyone,
I am tying to come up with an elegant way to process some input data
form tocome from a form. When the user hits the 'Submit' button, i want the
theappear again with the already entered valid data filled in and prompt
forward touser to re-enter the non-valid data. If all data is valid, i will
thean other .php page which enters the data into a database.
I tried to do this in the following way: the form always hits back on
itself, but when all data is valid i use the PHP:header() to redirect to
datadata.php that performs the database insertion. The problem is that the
thisis not available to data.php in the $_POST variable. How can i overcome
problem? Any other subtle way to handle the whole thing? Any help
appreciated.
I would break the function a little differently.
1. Have a form (view) that is sensitive to $SESSSION. That is, it will
use the values in SESSION to populate any dynamic values to be displayed
in the form.
2. Have another process (controller) that:
a) processes $_POST or $_GET
b) if all is valid, does the insert/update and redirects to another
page (Your data has been saved.)
c) if all is not valid, populates the $SESSION with good values and
then redirects to the view form.
The whole thing is started by calling the controller. Since no data is
valid, it will redirect to the view.
The view then presents a form for filling in.
The user fills in the form and submits which then calls the controller.
The controller processes the form data and either updates/inserts it or
calls the view again.
If you encapsulate your database accesses into a class or set of classes
which are called from the controller, you will have a light-weight
implementation of a classic Model-View-Controller (MVC2) architecture.
Thank you for your quick answer, i am heading towards the implementation you
suggested. Just another minor question: can i add an array variable to
SESSION? How can this be done?
.
- Follow-Ups:
- Re: Validating form input data
- From: David Haynes
- Re: Validating form input data
- References:
- Validating form input data
- From: stathis gotsis
- Re: Validating form input data
- From: David Haynes
- Validating form input data
- Prev by Date: Re: Validating form input data
- Next by Date: Re: Validating form input data
- Previous by thread: Re: Validating form input data
- Next by thread: Re: Validating form input data
- Index(es):