in reply to How to validate the form in CGI

I think the biggest problem is your invalid submit element:

<input type="submit" value="Submit" onsubmit=">

When you're making any sort of CGI program, especially one that uses JavaScript, you should do the following to debug:

  1. Connect to the CGI
  2. View the source.
  3. Look over the source for properly formed and valid HTML.
  4. Look over the enclosed JavaScript for proper validity. (or run it through a browser that will give good error messages on javascript problems)

That being said, you can never depend on a user having javascript turned on. If there is some sort of validation going on in the form, you should also validate it in the form backend, to make sure that the values are what you expect. (it may be that someone has JS turned off, or someone may be malicious and connect directly to your backend to try to force bad data on you).

Replies are listed 'Best First'.
Re^2: How to validate the form in CGI
by dorward (Curate) on Mar 08, 2005 at 13:22 UTC

    Look over the source for properly formed and valid HTML.

    But don't just eyeball it. There are tools to test it for you that are far less likely to miss things.

      Good point -- I shouldn't assume that everyone's using an editor that does syntax highlighting and validation.

      Some of the browsers have syntax coloring builtin when you view source, and there are a few that have built-in validators (iCab comes to mind). I've personally reset my source viewer with my text editor (BBEdit, as I'm a mac user). For those who haven't been writing HTML for more than a decade (damned <br> tag -- should've just made <address> preserve line endings)

      Anyway, there is a validation add-on for Mozilla, and there are even some validators in CPAN, like HTML::Validator and HTML::Tidy