Beispiel #1
0
 /**
  * Produce HTML output for all this fieldset and all contained controls
  *
  * @param Theme $theme
  * @return string HTML that will render this control in the form
  */
 function get(Theme $theme)
 {
     $this->settings['ignore_name'] = true;
     $controls = array();
     foreach ($this->controls as $control) {
         if ($class = $this->get_setting('class_each', '')) {
             $control->add_class($class);
         }
         if ($control instanceof FormContainer) {
             $control->set_template($this->get_setting('tab_template', 'control.fieldset.fortabs'));
             $controls[$control->caption] = $control->get($theme);
         }
     }
     $this->vars['controls'] = $controls;
     return parent::get($theme);
 }
Beispiel #2
0
 /**
  * Produce HTML output for all this fieldset and all contained controls
  *
  * @param boolean $forvalidation True if this control should render error information based on validation.
  * @return string HTML that will render this control in the form
  */
 function get(Theme $theme)
 {
     $this->vars['label'] = $this->label;
     $this->properties['for'] = reset($this->controls)->get_visualizer();
     return parent::get($theme);
 }
Beispiel #3
0
 /**
  * Produce the HTML for this control
  * @param Theme $theme The theme used for rendering
  * @return string The rendered control in HTML
  */
 function get(Theme $theme)
 {
     $this->settings['ignore_name'] = true;
     $this->vars['caption'] = $this->caption;
     return parent::get($theme);
 }
Beispiel #4
0
 /**
  * Get this control for display
  * @param Theme $theme The theme to use for rendering
  * @return string The output
  */
 public function get(Theme $theme)
 {
     $this->vars['element'] = $this->get_setting('wrap_element', 'div');
     return parent::get($theme);
 }
Beispiel #5
0
 /**
  * Produce a form with the contained fields.
  *
  * @param Theme $theme The theme to render the controls into
  * @return string HTML form generated from all controls assigned to this form
  */
 public function get(Theme $theme = null)
 {
     // Allow plugins to modify the form
     Plugins::act('modify_form_' . Utils::slugify($this->formtype, '_'), $this);
     Plugins::act('modify_form', $this);
     // Get the theme used to render the form
     if (is_null($theme)) {
         $theme = $this->get_theme();
     }
     $theme->start_buffer();
     $theme->success = false;
     $this->success = false;
     $this->submitted = false;
     $this->success_render = false;
     // Set the ID of the control explicitly if it's not already set
     $this->get_id();
     // If the form template wasn't explicitly set, set it, because this class' name can't be used to determine its template
     if (!isset($this->settings['template'])) {
         $this->set_template('control.form');
     }
     // If the action of this form wasn't explicitly set, unset it to avoid validation errors in output
     if (empty($this->properties['action'])) {
         unset($this->properties['action']);
     }
     // Add the control ID to the template output for the form
     $this->vars['_control_id'] = $this->control_id();
     // Load all of the initial values of controls from their storage locations
     $this->load();
     // If there was an error submitting this form before, set the values of the controls to the old ones to retry
     $this->set_from_error_values();
     // Is this form not a same-page duplicate?
     if (!$this->get_setting('is_dupe', false)) {
         // Was the form submitted?
         if (isset($_POST['_form_id']) && $_POST['_form_id'] == $this->control_id()) {
             $this->submitted = true;
             // Process all of the submitted values into the controls
             $this->process();
             // Do any of the controls fail validation?  This call alters the wrap
             $validation_errors = $this->validate();
             if (count($validation_errors) == 0) {
                 // All of the controls validate
                 $this->success = true;
                 // If do_success() returns anything, it should be output instead of the form.
                 $this->success_render = $this->do_success($this);
             } else {
                 if (isset($this->settings['use_session_errors']) && $this->settings['use_session_errors']) {
                     $this->each(function ($control) {
                         $control->errors = array();
                     });
                     foreach ($validation_errors as $error) {
                         Session::error($error);
                     }
                 }
             }
         } else {
             // Store the location at which this form was loaded, so we can potentially redirect to it later
             if (!$this->has_session_data() || !isset($_SESSION['forms'][$this->control_id()]['url'])) {
                 $_SESSION['forms'][$this->control_id()]['url'] = Site::get_url('habari', true) . Controller::get_stub() . '#' . $this->get_id(false);
             }
         }
         $output = $this->pre_out_controls();
         if ($this->success_render) {
             $output .= $this->success_render;
         } else {
             $output .= parent::get($theme);
         }
         if ($this->success && isset($this->settings['success_message'])) {
             $output .= $this->settings['success_message'];
         }
     } else {
         $output = parent::get($theme);
     }
     if (class_exists('\\tidy')) {
         $t = new \tidy();
         $t->parseString($output, array('indent' => true, 'wrap' => 80, 'show-body-only' => true));
         //$output = (string) $t;
     }
     return $output;
 }
 public function get(Theme $theme)
 {
     $primary = true;
     $controls = array();
     /** @var FormControlSubmit $control */
     foreach ($this->controls as $index => $control) {
         if ($control->is_enabled()) {
             $control->add_class('dropbutton_action');
             $control->add_class(Utils::slugify($control->input_name()));
             if ($primary) {
                 $control->add_class('primary');
                 $primary = false;
             }
             $controls[$index] = $control;
         }
     }
     if (count($controls) == 0) {
         return '';
     }
     $this->vars['first'] = array_shift($controls);
     $this->vars['actions'] = $controls;
     $this->set_template_properties('div', array('id' => $this->get_visualizer()));
     $this->add_template_class('ul', 'dropdown-menu');
     if (count($controls) > 0) {
         // Remember, these are in the dropmenu, doesn't include the first
         $this->add_template_class('div', 'has-drop');
     } else {
         $this->add_template_class('div', 'no-drop');
     }
     return parent::get($theme);
 }