Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] Error Handling Questions From: Manuel Lemos (mlemos <email protected>)
Date: 03/31/99

Hello Christian,

On 30-Mar-99 09:39:15, you wrote:

>I am currently struggling to find the best way to implement
>error checking and handling. I have data coming from a form.
>the PHP3 script checks values if they are correct. But how can
>I display an error message _and_ return the variables to the calling
>form so the user does not have to enter all values again ? (One field
>is a rather large text field) ...

What I do is to have the same script to handle the form by setting action
to the global variable $PHP_SELF. Then I use a hidden input to determine
if the form is being displayed for the first time or submitted for
processing. To determine that I check for that input variable (usually I
name it $doit). If I the script is processing a submitted form, I check if
the values are ok, if not the form is redisplayed, otherwise the requested
action is executed. Here'some pseudo-code.

if(form is being submitted)
{
        if(form values are not ok)
                flag_for_redisplay;
}
else
{
        flag_for_redisplay;
}
If(flag_for_redisplay)
        redisplay;
else
        perform_requested_action;

Has many people know I have written a class for PHP that process generates
and process forms from simple descriptions. It provides many built-in
types of both client (Javascript based) and server (PHP based) side
validation.

For server side validation it has a method that validates the field values
taken from the respective PHP global variables and returns an associative
array that lists all the fields that are wrong.

Anyway, if the user has a Javascript enabled browser he may never see the
form being redisplayed again as the generated Javascript code won't allow
the form to be submited if any field is determined to be invalid. In that case
a alert window is shown with the respective programmer defined error
message.

But you can't rely on all the users having a Javascript enabled browsers,
so server side validation must always be performed. Besides there are some
special kinds of validation that are hard to perform in Javascript like those
that require the server to check values in a database.

Mail me privately if you would like to get a copy of my class with a
working example.

Regards,
Manuel Lemos

E-mail: mlemos <email protected>
URL: http://www.e-na.net/the_author.html
PGP key: finger://mlemos <email protected>

--

-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3 List administrator: zeev-list-admin <email protected>