I apologize if this is stuff you already know, and I'm not trying to be patronizing, but I'd just like to put down some of my thoughts on the subject.

There is no way for a web server to talk to a web client without the web client having requested something. When you click on your "Submit" button, your web client sends a request to the web server to receive some data. Now, since your CGI script is sitting on the server, all it can do is passively wait for some data to be submitted to it. I'm sure you understand this, but it's worth reiterating.

By the time your CGI script gets the chance to do anything useful, the "whole page" has already been submitted. It's too late to say "wait wait, don't submit the page, but show a dialog box with an error instead." Thus your only realistic option is to "reload the whole page" with an error message. Now, as far as UI is concerned, at this point your error message can easily be displayed in a javascript popup window. This is not the issue. The issue is you want more integration between server and client than HTTP provides. This is a limitation you'll have to accept. Using tricks with frames may be an option, but might end up being more work than is feasible, and I usually try to avoid that kind of hack.

Of course, another solution is to move all this processing to the client, so you can check before the submit happens. You have already explained that you don't want to do this, though, so I only mention it in passing. (Also, even when used, this should not be relied upon. Clients don't have to execute JavaScript. Even if they did, one could hack up one's client to do whatever one pleases. The server-side processing would still be necessary for actual verification purposes; the client-side processing is merely a convenience to avoid unnecessary page reloads.)


In reply to Re: Re: Re: "alert" or prompt box from perl cgi script by revdiablo
in thread "alert" or prompt box from perl cgi script by argv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.