List:General Discussion« Previous MessageNext Message »
From:George Law Date:July 26 2006 5:30pm
Subject:RE: Checkboxes
View as plain text  

It looks like the mysql part has been answered.  I was going to suggest
using a ENUM
field myself.

For the PHP part, if you are trying to keep multiple rows in your HTML
ie $customer[1] = $mod_type[1] you may not want to use a checkbox field

checkbox fields only pass a field if they are checked - so if you have
for customer[0], and the checkbox is not checked, then $mod_type[0]
would NOT be from the first
row, it would be from the first CHECKED row.

The best solution I have found is to use a RADIO button with the value
set to the default. 
this way it always gets a value. I have seen others suggest to using a
hidden field
to preset this field so there is always a value -- 
<input type="hidden" name="mod_type_0" value="other"/>
<input type="checkbox" name="mod_type_0" value="alternative"
/>Alternative<br />)

This way, if the checkbox is unchecked, it gets a value of "other", but
if it is
checked, it will pass a value ot "alternative".

Note - I am not sure how this would work with an array (mod_type[]).
PHP might treat
the hidden field as index 0, and if the checkbox is checked, it would be
index 1


>>>-----Original Message-----
>>>From: Nicholas Vettese [mailto:nvettese@stripped] 
>>>Sent: Wednesday, July 26, 2006 12:04 PM
>>>To: mysql@stripped
>>>Subject: Checkboxes
>>>I am trying to allow a user to use checkboxes for multiple 
>>>selections, and I am trying to get the database to record 
>>>the choices made by the user.  I am using a VARCHAR(250), 
>>>but I am guessing that may be wrong.  Also, other than 
>>>adding a "[]" to the end of the 'name' (e.g. <input 
>>>type="checkbox" name="mod_type[]" value="alternative" 
>>>/>Alternative<br />), what do I need to do?
>>>I hope I am asking this question correctly.  If not, please 
>>>feel free to flame me.

CheckboxesNicholas Vettese26 Jul
  • Re: CheckboxesPeter Brawley26 Jul
  • Re: CheckboxesMartin Jespersen26 Jul
RE: CheckboxesGeorge Law26 Jul