function smarty_function_validation_errors($params, &$smarty)
{
    $default_params = array('for' => coalesce_key($params, 'for', null), 'header_message' => coalesce_key($params, 'header_message', '', FILTER_SANITIZE_STRING), 'header_tag' => coalesce_key($params, 'header_tag', 'h2', FILTER_SANITIZE_STRING), 'header_tag_class' => coalesce_key($params, 'header_tag_class', 'errorheader', FILTER_SANITIZE_STRING), 'div_tag_class' => coalesce_key($params, 'div_tag_class', 'pageerror', FILTER_SANITIZE_STRING), 'ul_tag_class' => coalesce_key($params, 'ul_tag_class', 'errorul', FILTER_SANITIZE_STRING), 'params' => coalesce_key($params, 'params', array()));
    //if ($check_keys && !are_all_keys_valid($params, $default_params))
    //	throw new SilkInvalidKeyException(invalid_key($params, $default_params));
    $params = array_merge($default_params, forms()->strip_extra_params($params, $default_params, 'params'));
    unset($params['params']);
    if ($params['for'] != null && is_object($params['for'])) {
        if (isset($params['for']->validation_errors) && is_array($params['for']->validation_errors) && count($params['for']->validation_errors) > 0) {
            echo '<div class="' . $params['div_tag_class'] . '">';
            if ($params['header_message']) {
                echo "<" . $params['header_tag'] . " class='" . $params['header_tag_class'] . "'>" . $params['header_message'] . "</" . $params['header_tag'] . ">";
            }
            echo '<ul class="' . $params['ul_tag_class'] . '">';
            foreach ($params['for']->validation_errors as $err) {
                echo '<li>' . $err . '</li>';
            }
            echo '</ul>';
            echo '</div>';
        }
    }
}
Esempio n. 2
0
 /**
  * Returns the xhtml equivalent of options tags.  This is basically a nice little wrapper
  * to make sure that id's are placed in names and also that it's xhtml compliant.\n
  * Parameters:
  * - 'items' - An associative array of key/values to represent the value and text of the items in the list.  This can also be
  *           passed a string in the form of 'key,value,key,value'.  Defaults to array().
  * - 'selected_value' - A string that will set the matching item (by value) as selected.  Defaults = ''.
  * - 'selected_index' - An integer that will set the matching item (by index) as selected.  Defaults to -1 (no selection).
  * - 'selected_values' - An array of strings that will set the matching item as selected.  This is for multiple select items.
  * - 'extra' - Text to append to the <input>-statement, ex. for javascript-validation code.  Defaults to ''.
  * - 'flip_items' - Boolean that tells whether or not the value and text of the given items should be swapped.  Defaults to false.
  *
  * @param array An array of parameters to pass to the method.  Unrecognized parameters will be added as attributes to the
  *        tag and merged correctly with anything in the 'params' key if passed.
  * @param boolean Test whether keys are all valid or not.  Not helpful if you're
  *        passing extra key/values along, but good for debugging.
  * @return string
  * @author Ted Kulp
  */
 public function create_input_options($params = array(), $check_keys = false)
 {
     $default_params = array('items' => coalesce_key($params, 'items', array()), 'selected_value' => coalesce_key($params, 'selected_value', '', FILTER_SANITIZE_STRING), 'selected_index' => coalesce_key($params, 'selected_index', -1, FILTER_SANITIZE_NUMBER_INT), 'selected_values' => coalesce_key($params, 'selected_value', array()), 'flip_items' => coalesce_key($params, 'flip_items', false, FILTER_VALIDATE_BOOLEAN), 'params' => coalesce_key($params, 'params', array()));
     if ($check_keys && !are_all_keys_valid($params, $default_params)) {
         throw new SilkInvalidKeyException(invalid_key($params, $default_params));
     }
     //Combine EVERYTHING together into a big managerie
     $params = array_merge($default_params, forms()->strip_extra_params($params, $default_params, 'params'));
     unset($params['params']);
     $selected_index = $params['selected_index'];
     unset($params['selected_index']);
     $selected_value = $params['selected_value'];
     unset($params['selected_value']);
     $selected_values = $params['selected_values'];
     unset($params['selected_values']);
     $items = $params['items'];
     unset($params['items']);
     if (!is_array($items) && strlen($items) > 0) {
         $ary = array_chunk(explode(',', $items), 2);
         $items = array();
         foreach ($ary as $one_item) {
             if (count($one_item) == 2) {
                 $items[$one_item[0]] = $one_item[1];
             }
         }
     }
     if ($params['flip_items']) {
         $items = array_flip($items);
     }
     unset($params['flip_items']);
     $text = '';
     $count = 0;
     foreach ($items as $k => $v) {
         $hash = array('value' => $k);
         if ($count == $selected_index || $k == $selected_value || in_array($k, $selected_values)) {
             $hash['selected'] = 'selected';
         }
         $text .= forms()->create_start_tag('option', $hash) . $v . forms()->create_end_tag('option');
         $count++;
     }
     return $text;
 }