Denver Web Design, Denver Web Development
PHP/MySQL experts in Colorado

Zend_Form multidimensional multicheckbox subform groups

24 September 2010

PHP web developers help (Zend_Form).

If you need to use multidimensional arrays for checkboxes in Zend Form, we would suggest you to use subform instead of group.
For example, you need this array:
$options=Array (

[windows] => Array (

[12] => Heated Mirror Glass

[11] => Power Mirrors

[8] => Power windows

[10] => Tinted Glass )

[sound] => Array (

[38] => AM / FM radio

[43] => Amplifier

[39] => CD Changer

[40] => CD Player

[41] => MP3 Player

[42] => Navigation System

[44] => Subwoofer )

[safety] => Array (

[45] => Anti-Lock Brakes

[46] => Driver Airbag

[50] => Electronic Stability Control

[53] => Fog Lights

[54] => Head Light Washer System

[51] => Parking - Assistance System

[47] => Passanger Airbag

[48] => Side Airbag

[49] => Side Curtain Airbag

[55] => Tire Pressure Monitoring

[52] => Xenon Lights )

[other] => Array (

[29] => Airconditioning

[28] => Alarm System

[26] => Alloy Wheels

[34] => Child Seat

[30] => Cruise Control

[37] => Heated Seats

[35] => Leather Seats

[27] => Luggage Rack

[33] => Power Door Locks

[36] => Power Seats

[31] => Power Steering

[32] => Sunroof ) ) ;


To be like one element in a form.  You can use following code to add it to your Zend_Form:

$key='opt';


$$key = new Zend_Form_SubForm ( );

$$key->setAttribs(array('legend' => $field ['label']));

if (is_array ( $options )){

foreach ( $options as $x => $val )

if(!empty($x))

$$key->addElement ( 'multicheckbox', $x, array ('label' => ucfirst($x), 'separator' => '', 'value' => $field ['value'][$x], 'class' => $field ['class'], 'required' => $field ['required'], 'filters' => array ('StringTrim' ), 'validators' => $field ['validators'], 'description' => $field ['Description'], 'multioptions' => $val ) );

}

$this->addSubForm($$key,$key);

by Nataly Tarasova
Nataly Tarasova


Leave a comment:
 
 
 

Archives

2011
2010