|
Posted by J.O. Aho on 10/13/02 11:29
Domestos wrote:
> Say a user inputs an invalid string into a field - say for example e-mail in
> a form on Page A...
>
> Validation is done on Page B. It notices that the e-mail is incorrect and
> informs the user and jumps them back to the form on Page A.
>
> To get the values the user had input in the e-mail and other fields on the
> form to re-display rather than a blank form I do the following...
>
> On Page B I set $_SESSION('back')=1 and set other variables like
> $_SESSION('name')=$name and $_SESSION('email')=$email
>
> on returning to PageA I check if $_SESSION('back') exists and if so set the
> $name and $email to the $_SESSION superglobals, if not I read the
> information in from a database. I then un-register $_SESSION('back') and the
> others...
>
> There must be a better way to do this!!!!
I usually have a wrapper page that the FORM is called from (include file), in
the wrapper page all the needed checks are done, while in the include files
you have what you want to display, the FORM or the result of the Submit, this
way you don't have to send things back and forth.
Do first checks if you have the "submit" value set and then see if the
required values has been set or not and then check that all the values are
okey, if no errors, then include_once() the result page, if you find an error,
save an error message to a variable and include_once() the form page which
will automatically fill the values
<INPUT TYPE='text' NAME='username' VALUE='<?PHP echo $username; ?>'>
If the "submit" hasn't been set, clear all the variables for the form, this so
that you won't get false values.
Of course you should include javascript that checks the input values when
pressing the submit button and should open an alarm requester telling what
data is missing and what data is not valid, this so that you don't send
incomplete data to the server. Of course only javascript checking wouldn't be
enough, as there are people who turns javascript support off.
//Aho
[Back to original message]
|