|
Posted by Chris Beall on 11/15/05 21:30
Ed Jay wrote:
> I generate a page using a Perl script ("Page 1"). The page has a
> multi-question form that is submitted to a second Perl script that creates
> the next page ("Page 2").
>
> Page 1 has a couple of questions that assigns values (0 or 1) to variable
> $A and to variable $B. $A and B$ cannot each have the value 1. I'm trying
> to trap the potential input error that results in $A = $B = 1.
>
> Clearly I can submit the form values to Page 2 and have Page 2 test for
> the error, print an error message and have the operator press a button to
> return to Page 1. IOW, read all variables sent from Page 1, test for the
> error, and if the error exists use a form to resubmit the form to
> Page 1, otherwise continue to process Page 2, as follows:
>
> E.g.,
>
> Submit Page 1 variables to Page 2
> Page 2 reads in variables from Page 1
> if ($A && $B != 1) {process Page 2} #then goto Page 3
> else {
> print the error message
> <FORM ACTION=cgi-bin/page_1.cgi\" METHOD=\"POST\">
> <input type=submit value="Press here to go back to Page 1">
> }
>
> I'd prefer to have the form automatically proceed back to Page 1 if
> there's an error instead of having the op press another button..
>
> Two questions:
>
> 1. How can I either test the error while still on Page 1?
>
> 2. How do I test for the Page 1 error on Page 2 and automatically return
> the op to Page 1 for corrections?
>
> Thanks.
>
Ed,
Reverse your logic:
If no input is present, Perl1 generates a blank-form HTML Page 1. On
Submit, return control to the SAME Perl1 code. That code validates the
input and, if valid, calls Perl2 to generate HTML Page 2, passing
parameters as needed. If the input is NOT valid, Perl1 regurgitates
HTML Page1, with all prior input unchanged, and with appropriate error
indications (red color, out-of-range message, etc.)
Each Perl module is therefore responsible for:
- Testing whether input is present (first-time not) ex: if (exists
$form{"parm1"})
- Generating an initial HTML page
- Fielding the user's response from that page
- Validating the user's input
- Passing control to the next module only if the input is valid
Chris Beall
Navigation:
[Reply to this message]
|