[Solar-talk] Solar Form help
Paul M Jones
pmjones at solarphp.com
Tue Nov 28 18:11:32 PST 2006
Hi Micahel, sorry for the late reply.
On Nov 16, 2006, at 2:40 PM, Michael Soule wrote:
> Is there an example somewhere of using an array of checkboxes with
> Solar Form?
>
> I want my checkboxes to render as:
>
> <input type="checkbox" name="beers[]" value="Bud" />
> <input type="checkbox" name="beers[]" value="Coors" />
> <input type="checkbox" name="beers[]" value="Heineken" />
> <input type="checkbox" name="beers[]" value="Kirin" />
>
> But I'm not sure how to accomplish this with the FormDescriptor array.
The issue is the naming; if they all have the same name, then the
Form object won't be able to differentiate them from each other. So
although it's valid to use the [] naming syntax for HTML, and PHP
itself will recognize it, the Solar_Form object can only handle one
[] at a time.
The solution, ugly though it may be, is to not use the [] sequential
shorthand, and actually assign keys to the FormDescriptor names. E.g.:
<input type="checkbox" name="beers[0]" value="Bud" />
<input type="checkbox" name="beers[1]" value="Coors" />
<input type="checkbox" name="beers[2]" value="Heineken" />
<input type="checkbox" name="beers[3]" value="Kirin" />
Does that help at all?
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Join the Solar community wiki! <http://solarphp.org>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list