Пример #1
0
 /**
  * @param FTL_Binding $tag
  *
  * @return string
  */
 public static function tag_form(FTL_Binding $tag)
 {
     if (!isset(self::$ci->form_validation)) {
         self::$ci->load->library('form_validation');
     }
     // Init once errors message
     if (!self::$_inited) {
         // Previously : Replace of CI standard error message by internal one.
         // Now : No chnages, no needs to.
         // self::_init_error_messages();
         self::$_inited = TRUE;
         // Posting form name
         if (self::$ci->input->post('form')) {
             self::$posting_form_name = self::$ci->input->post('form');
         }
         // Get forms settings
         $forms = self::get_form_settings();
         // Create dynamic tags regarding the declared forms
         foreach ($forms as $form => $settings) {
             self::$context->define_tag('form:' . $form, array(__CLASS__, 'tag_expand'));
             self::$context->define_tag('form:' . $form . ':validation', array(__CLASS__, 'tag_expand'));
             self::$context->define_tag('form:' . $form . ':validation:result', array(__CLASS__, 'tag_form_validation_result'));
             self::$context->define_tag('form:' . $form . ':validation:success', array(__CLASS__, 'tag_form_validation_success'));
             self::$context->define_tag('form:' . $form . ':validation:error', array(__CLASS__, 'tag_form_validation_error'));
             self::$context->define_tag('form:' . $form . ':posted', array(__CLASS__, 'tag_form_posted'));
             self::$context->define_tag('form:field:' . $form, array(__CLASS__, 'tag_expand'));
             self::$context->define_tag('form:radio:' . $form, array(__CLASS__, 'tag_expand'));
             self::$context->define_tag('form:checkbox:' . $form, array(__CLASS__, 'tag_expand'));
             self::$context->define_tag('form:select:' . $form, array(__CLASS__, 'tag_expand'));
             // Fields individual errors
             self::$context->define_tag('form:' . $form . ':error', array(__CLASS__, 'tag_expand'));
             // Form refill after error / Fields individual errors : one tag / field
             if (!empty($settings['fields'])) {
                 foreach ($settings['fields'] as $field => $field_setting) {
                     // Field Error string
                     self::$context->define_tag('form:' . $form . ':error:' . $field, array(__CLASS__, 'tag_form_error_value'));
                     // One method / field type
                     $type = empty($field_setting['type']) ? 'input' : $field_setting['type'];
                     switch ($type) {
                         case 'radio':
                             self::$context->define_tag('form:' . $form . ':radio:' . $field, array(__CLASS__, 'tag_form_radio_value'));
                             break;
                         case 'checkbox':
                             self::$context->define_tag('form:' . $form . ':checkbox:' . $field, array(__CLASS__, 'tag_form_checkbox_value'));
                             break;
                         case 'select':
                             self::$context->define_tag('form:' . $form . ':select:' . $field, array(__CLASS__, 'tag_form_select_value'));
                             break;
                         default:
                             self::$context->define_tag('form:' . $form . ':field:' . $field, array(__CLASS__, 'tag_form_field_value'));
                     }
                 }
             }
         }
     }
     return $tag->expand();
 }