Blank "select" field/FromCGI

[prev] [thread] [next] [Date index for 2004/09/11]

From: Jesse Sheidlower
Subject: Blank "select" field/FromCGI
Date: 17:16 on 11 Sep 2004
This may just be an HTML question, or a database issue, but
it's driving me crazy, so if anyone could help I'd be really
grateful.

I have a Maypole-based application where certain columns are
has_a relationships to other tables. In the database, these
columns are tinyints, and they can be NULL. I'm generating a
select list to add to these fields, and I'd like there to be
a blank row so that the user can choose not to enter a value
for these fields.

The HTML ends up looking like:

<tr><td>Format</td>
   <td><select name="format">
     <option></option>
     <option value=1>Hardcover</option>
     <option value=3>Pamphlet</option>
     <option value=2>Paperback</option>
   </select></td>
</tr>

This has the right visual appearance. However, when it gets
sent back, I get the value  'format' => '' (according to
Data::Dumper), and then when create_from_cgi does its thing
I end up with a "0" in the format field. Of course, I want
the format field to remain NULL if the user selects the
blank row.

This behavior is consistent across all of my has_a
relationships where the main table stores a tinyint. But I
note that this form also has some text fields, and when these
are sent back empty, the variables also have a value of '',
yet nothing is inserted into the database.

So, what do I need to do to ensure that nothing is inserted
into these columns when the select fields are blank?

I'm sure this is something really obvious, and probably not
related to CDBI, but it's probably also something that people
need to do with CDBI, so I'd be grateful for any advice.

Thanks,

Jesse Sheidlower

Blank "select" field/FromCGI
Jesse Sheidlower 17:16 on 11 Sep 2004

Re: Blank "select" field/FromCGI
Clayton Scott 17:25 on 11 Sep 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52