Link to home
Start Free TrialLog in
Avatar of bgodden
bgodden

asked on

Redisplaying form after submit error

Hi(sorry for the novel),
Currently my CGI displays an error message when there is an incorrect value submitted in the form and then asks the user to go back and enter the correct information into the form.  This doesn't always work well with certain browsers.  I would like to re-display the form below my error message and ensure that the fields they filled in are still there.

I thought of using the array of values obtained from the submittion and setting the form values to those values, but I have one sticky limitation: I have designed the cgi so that many areas of our website can use it and so that the various areas can customize a section that contains radio buttons for category selection.  To remain this flexible, I would have to capture that section from the submitting page and rewrite, setting the user-checked value to checked...

Is there a simpler way to redisplay the form with it's current values, including the appropriate error message, without have to go through these hoops?
Thanks for any help...
Avatar of slok
slok

What do you use to write your cgi with?
Information on that will be useful.
Avatar of bgodden

ASKER

Bumping up the points...
Avatar of bgodden

ASKER

Oops, didn't see the comment.  The cgi is written in perl, currently the error page is in a subroutine which is called by the input data verification subroutine and is passed the specific error message, then the page is output form there...
Make your script output lines like:

print "<INPUT TYPE="radio" ... CHECKED>";

This way your radio button will be showd selected.

The same method works for checkboxes.

Regards, julio
Avatar of bgodden

ASKER

Well,  My situation is a little more dynamic then that, I allow publishers from various areas of the site to customize their own radio buttons so I will need to capture the submitting page and suck their radio button section off that page, then output the correct one of that set that has been checked as julio has mentioned above...  Does anyone know of a simpler way to approach this?
Thanks for your response julio...Brian
I don't know if this is of any help to you, but it is what I do in similar circumstances.

I arrange matters so that the script that carries out the validation process (e.g. script.pl) will also draw the input form. The script therefore has three main sections.

1. The first time in, it creates default values for the various form entries (e.g. by reading data from a file or by giving null values). It then displays the form.

2. Every time it detects an error it prints the error message at the top of the page. It then displays the form using the values passed to it from stage 1.

3. When there are no errors it finally processes the data and gives a confirmation text, obviously in this case it does not re-display the form.

The script can detect the difference between the first time in and cases 2 and 3 by looking at the value returned from the submit button.

I handle radio buttons by defining them in the following way.
(Section of my code follows).

$period = $in{period}; # input previous radio state
$period = "W" unless $period; # Give default radio value
eval "\$period$period = \"CHECKED\"";
# some code omitted for clarity

print <<__STATS_END__;
# some code omitted for clarity
<input type="radio" name="period" $periodW value="W">week<br>
<input type="radio" name="period" $periodY value="Y">year<br>
# some code omitted for clarity
__STATS_END__

Now you don't state how the 'customization' by your customers is achieved so I don't know if this approach would be suitable for you.

Avatar of bgodden

ASKER

icd,  thanks for your input.  I've already rolled out a different version of this that mainly works with separate files, i.e. each area has it's own feedback.html form page and it's own success.html confirmatiuon page.  This was to allow them to make cosmetic and content changes, including the different radio buttons, which in my script I simply look for $FEEDBACK{"type"}, then tag their subect field with the type specified.  It looks like I'm going to need to capture the submitting page when data is submitted so that I can redisplay their radio buttons in the event of an error...
ASKER CERTIFIED SOLUTION
Avatar of delvin
delvin
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial