Example #1
0
 /**
  * Constructor
  *
  * Instantiate the set of checkbox input form elements
  *
  * @param  string       $name
  * @param  array        $values
  * @param  string       $indent
  * @param  string|array $marked
  * @return CheckboxSet
  */
 public function __construct($name, array $values, $indent = null, $marked = null)
 {
     if (null !== $marked) {
         if (!is_array($marked)) {
             $marked = [$marked];
         }
     } else {
         $marked = [];
     }
     parent::__construct('fieldset', null, null, false, $indent);
     $this->attributes['class'] = 'checkbox-fieldset';
     $this->setMarked($marked);
     $this->setName($name . '[]');
     // Create the checkbox elements and related span elements.
     $i = null;
     foreach ($values as $k => $v) {
         $checkbox = new Input\Checkbox($name . '[]', null, $indent);
         $checkbox->setAttributes(['class' => 'checkbox', 'id' => $name . $i, 'value' => $k]);
         // Determine if the current radio element is checked.
         if (in_array($k, $this->marked)) {
             $checkbox->setAttribute('checked', 'checked');
         }
         $span = new Child('span', null, null, false, $indent);
         $span->setAttribute('class', 'checkbox-span');
         $span->setNodeValue($v);
         $this->addChildren([$checkbox, $span]);
         $this->checkboxes[] = $checkbox;
         $i++;
     }
     $this->value = $values;
 }
 public function form()
 {
     $country_name = new Input\Text('lace-zone-name');
     $country_name->setLabel('Zone Name:')->setRequired(true)->addValidator(new Validator\Alpha());
     $country_zone_code = new Input\Text('lace-zone-code');
     $country_zone_code->setLabel('ISO Code 3:')->setRequired(true)->setAttribute('maxlength', '3')->addValidators([new Validator\Alpha(), new Validator\Length(3)]);
     $enabled = new Input\Checkbox('lace-enabled', '1');
     $enabled->setLabel('Enable:');
     $submit = new Input\Submit('submit', 'SUBMIT');
     //Adding Elements to form
     $this->form->addElements([$country_name, $country_zone_code, $enabled, $submit]);
     return $this->form;
 }
 public function form()
 {
     $country_name = new Input\Text('lace-country-name');
     $country_name->setLabel('Country Name:')->setRequired(true)->addValidator(new Validator\Alpha());
     $country_iso_3 = new Input\Text('lace-country-iso3');
     $country_iso_3->setLabel('ISO Code 3:')->setRequired(true)->setAttribute('maxlength', '3')->addValidators([new Validator\Alpha(), new Validator\Length(3)]);
     $country_iso_2 = new Input\Text('lace-country-iso2');
     $country_iso_2->setLabel('ISO Code 2:')->setRequired(true)->setAttribute('maxlength', '2')->addValidators([new Validator\Alpha(), new Validator\Length(2)]);
     $postcode_required = new Input\Checkbox('lace-postcode', '1');
     $postcode_required->setLabel('Post Code Required:');
     $enabled = new Input\Checkbox('lace-enabled', '1');
     $enabled->setLabel('Enable:');
     $submit = new Input\Submit('submit', 'SUBMIT');
     //Adding Elements to form
     $this->form->addElements([$country_name, $country_iso_3, $country_iso_2, $postcode_required, $enabled, $submit]);
     return $this->form;
 }