CGI question on input type=text form elements

DeepBlue DeepBlue at DeepBlue.org
Thu Oct 11 15:52:10 EDT 2001


"Ignacio Vazquez-Abrams" <ignacio at openservices.net> wrote in message
news:mailman.1002823931.18186.python-list at python.org...
> On Thu, 11 Oct 2001, DeepBlue wrote:
>
> >
> > "Ignacio Vazquez-Abrams" <ignacio at openservices.net> wrote in message
> > news:mailman.1002815363.21257.python-list at python.org...
> > > On Thu, 11 Oct 2001, DeepBlue wrote:
> > >
> > > > I am running into a strange problem with a form while using CGI
module
> > in
> > > > Python.
> > > > Let us say I have the following form:
> > > > <form>
> > > > <input type="text" name="text_1">
> > > > <input type="submit" name="submit" value="test">
> > > > </form>
> > > >
> > > > Now, let us say that test_form=cgi.FieldStorage()
> > > > If the above form is submitted without typing anything in the text
field
> > one
> > > > expects test_form.keys() to generate:
> > > > ['submit']
> > > >
> > > > But i am getting:
> > > > ['text_1', 'submit']
> > > > Which is unexpected, and in my case, undesirable.  What am I doing
> > wrong?
> > >
> > > You are assuming that the browser won't pass the contents of text_1 if
it
> > is
> > > empty. Obviously this isn't true. You need to fine-tune your code to
deal
> > with
> > > the case when it is empty.
> > >
> > This is only happening when the form is enclosed in a table.  When the
form
> > is not, the keys do not include empty text input elements.
>
> Well then you have two options:
>
> 1) Let the Python script know when the form is in a table, or
>
> 2) Deal with cases when the field is present but empty
>
> Not only is option 2 probably easier, but it's also the "correct" thing to
do,
> because other browsers may behave in a different manner, returning the
empty
> field whether or not the input is in a table.
>
I know that 2 is much easier; and after what happened I am getting into the
habit of checking on all keys and to check if they are empty:
I only thought it was strange that the key of an empty element was included
as a key when the form happens to be in a table.
DB





More information about the Python-list mailing list