Exemple #1
0
 public static function register(Fieldset $form)
 {
     $form->add('email', 'E-mail:')->add_rule('required')->add_rule('valid_email');
     $form->add('password', 'Choose Password:'******'type' => 'password'))->add_rule('required');
     $form->add('password2', 'Re-type Password:'******'type' => 'password'))->add_rule('required');
     $form->add('submit', ' ', array('type' => 'submit', 'value' => 'Register'));
     return $form;
 }
Exemple #2
0
 public static function populate_register_fieldset(Fieldset $form)
 {
     $form->add('username', 'Username:'******'class' => 'form-control'))->add_rule('required');
     $form->add('password', 'Choose Password:'******'type' => 'password', 'class' => 'form-control'))->add_rule('required');
     $form->add('password2', 'Re-type Password:'******'type' => 'password', 'class' => 'form-control'))->add_rule('required');
     $form->add('email', 'E-mail:', array('class' => 'form-control'))->add_rule('required')->add_rule('valid_email');
     $form->add('submit', ' ', array('type' => 'submit', 'value' => 'Register', 'class' => 'btn btn-primary'));
     return $form;
 }
Exemple #3
0
 public function getRadioCheckbox($renderApi, $unit, $fieldId, $postRequestValue = null, $required = false)
 {
     $formField = new \Fieldset();
     $listOptions = $this->listOptions->getListOptions($renderApi, $unit);
     $inputName = strlen($renderApi->getFormValue($unit, 'inputName')) > 0 ? $renderApi->getFormValue($unit, 'inputName') . "[]" : $fieldId . "[]";
     if ($listOptions->hasOptions()) {
         $optionCount = 0;
         $options = $listOptions->getOptions();
         $optionsLength = count($options);
         foreach ($options as $option) {
             /* @var $option \Option */
             $properties = $unit->getFormValues();
             if ($properties["listType"] === \ListType::RADIO) {
                 $choiceField = new \RadioButtonField();
             } elseif ($properties["listType"] === \ListType::CHECKBOX) {
                 $choiceField = new \CheckboxField();
             }
             $optionId = $fieldId . '_' . $optionCount;
             $elementProperties = $choiceField->getElementProperties();
             $elementProperties->addAttribute("value", $option->getValue());
             $elementProperties->addAttribute("name", $inputName);
             $elementProperties->addAttribute("id", $optionId);
             // set required attribute for radio options or when there is only one checkbox
             // don't set for multiple checkboxes to match server-side validation logic
             if ($required && ($properties["listType"] === \ListType::RADIO || $optionsLength === 1)) {
                 $elementProperties->addAttribute("required", null);
             }
             $request = new Request();
             $request->isPostRequest();
             if (!$request->isPostRequest() && $option->isChecked() || !is_null($postRequestValue) && in_array($option->getValue(), $postRequestValue)) {
                 $elementProperties->addAttribute("checked", null);
             }
             $label = new \Label();
             $label->add($choiceField);
             $label->add(new \Span($option->getName()));
             $labelProperties = $label->getElementProperties();
             $labelProperties->addAttribute("for", $optionId);
             $formField->add($label);
             $optionCount++;
         }
     }
     if ($this->formSubmit->isValid($renderApi, $unit) && !$this->isValidValue($unit, $postRequestValue)) {
         $formField->add($this->getErrorMessage($unit, $postRequestValue));
         $formField->getElementProperties()->addClass('vf__error');
     }
     return $formField;
 }
 /**
  * Alias for $this->fieldset->add()
  */
 public function add($name, $label = '', array $attributes = array(), array $rules = array())
 {
     return $this->fieldset->add($name, $label, $attributes, $rules);
 }
 /**
  * Display all options
  * @return void
  */
 function viewAll()
 {
     global $DB, $USER;
     $r = $DB->config->get(array('type!' => 'not_editable'), false, false, 'section,property');
     $form = new Form();
     $e = $this->may($USER, EDIT);
     $lastSectionName = false;
     $lastSection = false;
     $sections = array();
     while ($c = Database::fetchAssoc($r)) {
         if ($lastSectionName != $c['section']) {
             $lastSectionName = $c['section'];
             if ($lastSection != false && $lastSection->count() == 0) {
                 array_pop($sections);
             }
             $sections[] = $lastSection = new Fieldset(ucwords(str_replace('_', ' ', $c['section'])));
         }
         $mult = false;
         $a = false;
         switch ($c['type']) {
             case 'CSV':
                 if (is_array($c['value'])) {
                     $c['value'] = @join(',', $c['value']);
                 }
             case 'text':
                 if ($e) {
                     $a = new Input(ucwords(__(str_replace('_', ' ', $c['property']))), 'conf[' . $c['section'] . '][' . $c['property'] . ']', $c['value'], null, __($c['description']));
                 } else {
                     $a = '<span class="property">' . ucwords(__(str_replace('_', ' ', $c['property']))) . ':</span> <span class="value">' . $c['value'] . '</span><span class="description">' . __($c['description']) . '</span>';
                 }
                 break;
             case 'password':
                 if ($e) {
                     $a = new Password(ucwords(__(str_replace('_', ' ', $c['property']))), 'conf[' . $c['section'] . '][' . $c['property'] . ']', '********', null, __($c['description']));
                 } else {
                     $a = '<span class="property">' . ucwords(__(str_replace('_', ' ', $c['property']))) . ':</span> <span class="value">********</span><span class="description">' . __($c['description']) . '</span>';
                 }
                 break;
             case 'set':
                 $mult = true;
             case 'select':
                 if (is_array($c['set'])) {
                     if ($e) {
                         $a = new Select(ucwords(__(str_replace('_', ' ', $c['property']))), 'conf[' . $c['section'] . '][' . $c['property'] . ']', array_map('__', $c['set']), $c['value'], $mult, false, false, __($c['description']));
                     } else {
                         $a = '<span class="property">' . ucwords(__(str_replace('_', ' ', $c['property']))) . ':</span> <span class="value">' . @$c['set'][$c['value']] . '</span><span class="description">' . __($c['description']) . '</span>';
                     }
                 }
                 break;
             case 'check':
                 if ($e) {
                     $a = new Checkbox(ucwords(__(str_replace('_', ' ', $c['property']))), 'conf[' . $c['section'] . '][' . $c['property'] . ']', $c['value'], $c['value'], false, __($c['description']));
                 } else {
                     $a = '<span class="property">' . ucwords(__(str_replace('_', ' ', $c['property']))) . ':</span> <span class="value">' . $c['value'] . '</span><span class="description">' . __($c['description']) . '</span>';
                 }
                 break;
         }
         if ($a) {
             $lastSection->add($a);
         }
     }
     if ($lastSection != false && $lastSection->count() == 0) {
         array_pop($sections);
     }
     if ($e) {
         return $form->collection($sections);
     } else {
         return join('', $sections);
     }
 }
Exemple #6
0
 /**
  * @param   Fieldset  Fieldset to assign the field to
  * @return  Fieldset_Field
  * @throws  \RuntimeException
  */
 public function set_fieldset(Fieldset $fieldset)
 {
     // if we currently have a fieldset
     if ($this->fieldset) {
         // remove the field from the fieldset
         $this->fieldset->delete($this->name);
     }
     // add this field to the new fieldset
     $fieldset->add($this);
     // swap fieldsets
     $this->fieldset = $fieldset;
     return $this;
 }