Re: Validating form input data
- From: David Haynes <david.haynes2@xxxxxxxxxxxx>
- Date: Sun, 30 Apr 2006 10:29:24 -0400
stathis gotsis wrote:
"David Haynes" <david.haynes2@xxxxxxxxxxxx> wrote in message
news:Mp25g.739$jE6.350@xxxxxxxxxxxxxxxxxxxxxxxx
stathis gotsis wrote:thatHello everyone,
I am tying to come up with an elegant way to process some input dataform tocome from a form. When the user hits the 'Submit' button, i want thetheappear again with the already entered valid data filled in and promptforward touser to re-enter the non-valid data. If all data is valid, i willthean 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 thethisis not available to data.php in the $_POST variable. How can i overcomeproblem? Any other subtle way to handle the whole thing? Any helpI would break the function a little differently.
appreciated.
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?
$my_array = array('one' => 1, 'two' => 2);
$_SESSION['my_array'] = $my_array;
or
$_SESSION['my_array'] = array('one' => 1, 'two' => 2);
-david-
.
- References:
- Validating form input data
- From: stathis gotsis
- Re: Validating form input data
- From: David Haynes
- Re: Validating form input data
- From: stathis gotsis
- Validating form input data
- Prev by Date: Re: Validating form input data
- Next by Date: Re: MYSQL table backups
- Previous by thread: Re: Validating form input data
- Next by thread: Re: Validating form input data
- Index(es):