/** * 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 ); }
/** * This function is used by {@link param_error()} and {@link param_error_multiple()}. * * If {@link $link_param_err_messages_to_field_IDs} is true, it will link those parts of the * error message that are not already links, to the html IDs of the fields with errors. * * @param string param name * @param string error message */ function param_add_message_to_Log($var, $err_msg, $log_category = 'error') { global $link_param_err_messages_to_field_IDs; global $Messages; if (!empty($link_param_err_messages_to_field_IDs)) { $var_id = Form::get_valid_id($var); $start_link = '<a href="#' . $var_id . '" onclick="var form_elem = document.getElementById(\'' . $var_id . '\'); if( form_elem ) { if(form_elem.select) { form_elem.select(); } else if(form_elem.focus) { form_elem.focus(); } }">'; // "SELECT" does not have .select() if (strpos($err_msg, '<a') !== false) { // there is at least one link in $err_msg, link those parts that are no links $err_msg = preg_replace('~(\\s*)(<a\\s+[^>]+>[^<]*</a>\\s*)~i', '</a>$1»$2' . $start_link, $err_msg); } if (substr($err_msg, 0, 4) == '</a>') { // There was a link at the beginning of $err_msg: we do not prepend an emtpy link before it $Messages->add(substr($err_msg, 4) . '</a>', $log_category); } else { $Messages->add($start_link . $err_msg . '</a>', $log_category); } } else { $Messages->add($err_msg, $log_category); } }