Resubmitting form after error

Posted on 1998-07-14
Last Modified: 2013-12-25
My cgi is in perl on a unix webserver.  I have a special configuration where I allow area publishers to have their own custom areas on their feedback pages then they can submit to my cgi.

I wish to add a feature that re-displays the form when a field is missed or other error occurs so that the user does not need to go back and, depending on their browser/configuration, re-type *all* their information.
Everything is working correctly including re-displaying the custom sections and the previous values of the fields that were entered correctly, radio buttons that were checked, etc.
But I am encountering, I fear, a fatal problem.
When I go to re-submit the form I get the "Document contains no data" error in Netscape and a blank screen in Explorer.

I'm assuming this is related to the data that is displayed in the browser(the new page) being lost when the cgi is again accessed.

I would like to try to find a solution that does not use javascript, cgiwrappers, or that sort.  It needs to be browser independent.  Also, sometimes the data such as in the comments field can be quite long(in characters) so I don't think using the URL to re-submit the values will be effective...

Any help here would be greatly appreciated, if you need to see code, please be specific on the part you wish to see and I will display it(cause the script is rather long :-).
Question by:bgodden
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1830759
is the second page calling the correct program again (I assume it's the same program)?
If you're using relative addressing of the location for the program to be called (in the <FORM ACTION="....."> part, that might be causing a problem.  Definitely using absolute addressing is the way to go.

If this all works, I can't think of anything else until I see some code.

Expert Comment

ID: 1830760
Your design, as decribed, should work just fine. "Document contains no data" is often due to the called script failing with an error after it prints the headers.

So is it possible that something different about the data from the second submittal is crashing the script? It's very tough to know where to look without seeing it.

Are you trying to validate the REFERER? That would be different the second time and might cause your processing to be different.

To debug, try printing status messages in your script so you can get an idea of how far it's getting and what is failing.

Another idea is to change the METHOD=POST in the form to METHOD=GET, so you can see more easily how the the form values passed to the script the second time differ.

Let us know...

Expert Comment

ID: 1830761
This should work, it must be some small bug in your program, most likely in the form action tag.
Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.


Author Comment

ID: 1830762
OK, so this might be a further clue, I changed the FORM ACTION directory to the actual absolute path rather than the web root relative path and this time I got:
"Method not implemented
POST to /NextLibrary/WebServer/cgi-bin/process_feedback.cur not supported."
After the second submittal. Does this help anyone? It does certainly look like a bug in the form action.  I wanted to let you guys see this and I will go to work on some of alamo's suggestions to try to weed it out...
As far as the REFERER goes, I use it during the first submittal, then I save it in a hidden value on the re-written page and use it for subsequent submittals, like so:
This is where the REFERER page is processed:
sub get_page
      if ( $FEEDBACK{"refpage"} eq "" )
            $submit_pg = "$ENV{'HTTP_REFERER'}";
            $subdir = substr $submit_pg, 24;
            $rootrel = "/NextLibrary/WebServer/htdocs$subdir";
            $rootrel = '/NextLibrary/WebServer/htdocs$FEEDBACK{"refpage"}';
      return $rootrel;

And then written to the error page as:
<INPUT TYPE="HIDDEN" NAME="refpage" VALUE="$subdir">

Is this value being lost in the process?

Expert Comment

ID: 1830763
The form action in the html your script prints should call your script again... is your script really /NextLibrary/WebServer/cgi-bin/process_feedback.cur?

How does the form tag printed by the script differ from the form tag in the original html that calls it?

As to REFERER - you are actually doing what I had in mind (saving the original REFERER in a hidden field) but the way you are getting teh value in the first place is extremely unreliable... $subdir = substr $submit_pg, 24; without checking that the first 24 characters are what you expect will inevitably lead to problems. Plus, you set $subdir inside a Sub as a global that magically gets included in the html in a different part of the program, another thing that could break easily. If you aren't going to include the entire $rootrel as the hidden field (easier) then at least pass $subdir back and add the path when needed.

Author Comment

ID: 1830764
The form tag I use in the original is "/cgi-bin/process_feedback.cur".  However, following your advice, I think I may have narrow the problem down to something with the array element that holds the $subdir value, on the second submittal, it is not being resolved.  Also, thanks for your other suuggestions, I'll see if I can make this sub more reliable...  Stay tuned, if I debug this soon I'll send the points your way alamo :)

Author Comment

ID: 1830765
Bingo!  Looks like my problems were mainly due to some single-quotes where I needed double-quotes.  I want to accept alamo's comment, but don't see here where to do this, alamo, you may need to re-submit a comment(?)

Accepted Solution

alamo earned 500 total points
ID: 1830766
Congratulations on getting it working!

As you now see, you can't grade me until I post an answer, so here it is. For those who were crazy enough to pay 50 points to read this as a PAQ, read the comments :-)

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

615 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