Exemplo n.º 1
0
 /**
  * Extract common params out of $field_params into {@link $_common_params} and unsets them in $field_params.
  *
  * Also handles adding errors to the note.
  *
  * @access protected
  * @param array An array passed to a field generating function like {@link text_input()}. By reference!
  * @param string|NULL The name of the field. If not empty it gets used to build the id attribute.
  */
 function handle_common_params(&$field_params, $field_name = NULL, $field_label = NULL, $field_note = NULL)
 {
     #pre_dump( 'handle_common_params (before)', $field_params );
     $this->_common_params = array();
     // Reset
     // Copy optional variables, if given:
     if (isset($field_name)) {
         $field_params['name'] = $field_name;
     }
     if (isset($field_label)) {
         $field_params['label'] = $field_label;
     }
     if (isset($field_params['note'])) {
         $this->_common_params['note'] = $field_params['note'];
         unset($field_params['note']);
         // no HTML attribute
     } elseif (isset($field_note)) {
         $this->_common_params['note'] = $field_note;
     } else {
         $this->_common_params['note'] = NULL;
     }
     if (isset($field_params['note_format'])) {
         $this->_common_params['note_format'] = $field_params['note_format'];
         unset($field_params['note_format']);
         // no HTML attribute
     } else {
         $this->_common_params['note_format'] = $this->note_format;
     }
     if (isset($field_params['label'])) {
         $this->_common_params['label'] = $field_params['label'];
         unset($field_params['label']);
         // no HTML attribute
     } else {
         $this->_common_params['label'] = '';
     }
     if (isset($field_params['clickable_label'])) {
         $this->_common_params['clickable_label'] = $field_params['clickable_label'];
         unset($field_params['clickable_label']);
         // no HTML attribute
     } else {
         $this->_common_params['clickable_label'] = true;
     }
     if (isset($field_params['field_prefix'])) {
         $this->_common_params['field_prefix'] = $field_params['field_prefix'];
         unset($field_params['field_prefix']);
     }
     if (isset($field_params['field_suffix'])) {
         $this->_common_params['field_suffix'] = $field_params['field_suffix'];
         unset($field_params['field_suffix']);
     }
     if (isset($field_params['required'])) {
         $this->_common_params['required'] = $field_params['required'];
         unset($field_params['required']);
     }
     if (!empty($field_params['name'])) {
         if (!isset($field_params['id'])) {
             // Autogenerate id attrib (not for hidden, radio and submit types)
             if (empty($field_params['type']) || $field_params['type'] != 'hidden' && $field_params['type'] != 'radio' && $field_params['type'] != 'submit') {
                 // Save ID with field_params and _common_params (for get_label())
                 $field_params['id'] = $this->_common_params['id'] = Form::get_valid_id($field_params['name']);
             }
         } else {
             $this->_common_params['id'] = $field_params['id'];
         }
         // Remember the field name, so hiddens_by_key can skip it.
         $this->included_input_field_names[] = $field_params['name'];
     }
     // Mark required fields:
     if (isset($this->_common_params['required']) && $this->_common_params['required']) {
         // add "field_required" class:
         if (isset($field_params['type']) && $field_params['type'] == 'checkbox') {
             // checkboxes need a span
             $field_params['input_prefix'] = (isset($field_params['input_prefix']) ? $field_params['input_prefix'] : '') . '<span class="checkbox_required">';
             $field_params['input_suffix'] = '</span>' . (isset($field_params['input_suffix']) ? $field_params['input_suffix'] : '');
         } else {
             $field_params['class'] = isset($field_params['class']) ? $field_params['class'] . ' field_required' : 'field_required';
         }
     }
     // Error handling:
     if (isset($field_params['name']) && param_has_error($field_params['name'])) {
         // There is an error message for this field:
         if (isset($field_params['type']) && $field_params['type'] == 'checkbox') {
             // checkboxes need a span
             $field_params['input_prefix'] = (isset($field_params['input_prefix']) ? $field_params['input_prefix'] : '') . '<span class="checkbox_error">';
             $field_params['input_suffix'] = '</span>' . (isset($field_params['input_suffix']) ? $field_params['input_suffix'] : '');
         } else {
             $field_params['class'] = isset($field_params['class']) ? $field_params['class'] . ' field_error' : 'field_error';
         }
         if ($this->disp_param_err_messages_with_fields) {
             $this->_common_params['note'] .= ' <span class="field_error">' . param_get_error_msg($field_params['name']) . '</span>';
         }
     }
     if (isset($field_params['wide']) && $field_params['wide']) {
         $this->_common_params['wide'] = $field_params['wide'];
         unset($field_params['wide']);
     }
     if (isset($field_params['inline']) && $field_params['inline']) {
         $this->_common_params['inline'] = $field_params['inline'];
         unset($field_params['inline']);
     }
     #pre_dump( 'handle_common_params (after)', $field_params );
 }
Exemplo n.º 2
0
         if (!empty($login)) {
             $SQL = new SQL('Validate if username is available');
             $SQL->SELECT('user_ID');
             $SQL->FROM('T_users');
             $SQL->WHERE('user_login = "******"');
             if ($DB->get_var($SQL->get())) {
                 // Login already exists
                 echo 'exists';
             } else {
                 // Login is available
                 echo 'available';
             }
         }
     } else {
         // Incorrect format of login
         echo param_get_error_msg('login');
     }
     break;
 case 'results':
     // Refresh a results table (To change page, page size, an order)
     /**
      * Variable to define a current request as ajax content
      * It is used to don't display a wrapper data such as header, footer and etc.
      * @see is_ajax_content()
      *
      * @var boolean
      */
     $ajax_content_mode = true;
     // get callback function param, this function will display the results content
     $callback_function = param('callback_function', 'string', '');
     if (param('is_backoffice', 'integer', 0)) {