Solved

Redisplaying form after submit error

Posted on 1998-02-17
8
237 Views
Last Modified: 2013-12-25
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...
0
Comment
Question by:bgodden
8 Comments
 
LVL 3

Expert Comment

by:slok
ID: 1832017
What do you use to write your cgi with?
Information on that will be useful.
0
 

Author Comment

by:bgodden
ID: 1832018
Bumping up the points...
0
 

Author Comment

by:bgodden
ID: 1832019
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...
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1832020
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
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:bgodden
ID: 1832021
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
0
 
LVL 5

Expert Comment

by:icd
ID: 1832022
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.

0
 

Author Comment

by:bgodden
ID: 1832023
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...
0
 

Accepted Solution

by:
delvin earned 250 total points
ID: 1832024
What about using a javascript to place a button on the error page that allows the user to go back to the original form, with the curent values, and type in the necessary information.  It would simulate pressing the "back" button on the browser.  It would not display the error message, but since the person already seen the message they know what fields were missed, or what they did wrong.

Your javascript can even be palced directely in the <input> tage:

<Input Type=Button Value="Correct Form" onClick="location.back()">

Just an idea.  Does the error screen being on the screen add that much value to the site?


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now