예제 #1
0
 /**
  * Given a has of key/value pairs, generates and redirects to a URL
  * for this application.  Takes the same parameters as
  * SilkResponse::create_url.
  *
  * @param array List of parameters used to create the url
  * @return void
  * @author Ted Kulp
  **/
 public static function redirect_to_action($params = array())
 {
     SilkResponse::redirect(SilkResponse::create_url($params));
 }
예제 #2
0
 /**
  * Returns the xhtml equivalent of an submit button.  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:
  * - 'name' - The name of the field.  Defaults to 'input'.
  * - 'value' - The value (text) of the button.  Defaults to ''.
  * - 'extra' - Text to append to the <input>-statement, ex. for javascript-validation code.  Defaults to ''.
  * - 'html_id' - Id to use for the html id="".  Defaults to an autogenerated value.
  * - 'image' - The name of an image to display instead of the text.  Defaults to ''.
  * - 'confirm_text' - If set, a message to display to confirm the click.  Defaults to ''.
  * - 'params' - An array of key/value pairs to add as attributes to the input tag.  These will merge into any
  *      additional parameters you pass along in to the $params hash that aren't parsed by the function.
  * - 'reset' - Boolean of whether or not this is a reset buton.  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.
  * @return string
  * @author Ted Kulp
  */
 public function create_link($params = array())
 {
     $tag_params = array('text' => coalesce_key($params, 'text', '', FILTER_SANITIZE_STRING), 'onclick' => coalesce_key($params, 'onclick', ''), 'only_href' => coalesce_key($params, 'only_href', false, FILTER_VALIDATE_BOOLEAN), 'remote' => coalesce_key($params, 'remote', false, FILTER_VALIDATE_BOOLEAN), 'confirm_text' => coalesce_key($params, 'confirm_text', '', FILTER_SANITIZE_STRING), 'params' => coalesce_key($params, 'params', array()));
     $tag_params['id'] = coalesce_key($params, 'html_id', '', FILTER_SANITIZE_STRING);
     if ($tag_params['id'] != '') {
         $tag_params['id'] = SilkResponse::make_dom_id($tag_params['id']);
     } else {
         unset($tag_params['id']);
     }
     $url_params = forms()->strip_extra_params($params, $tag_params, 'params');
     unset($tag_params['params']);
     $tag_params['href'] = SilkResponse::create_url($url_params);
     if ($tag_params['only_href'] == true) {
         return $tag_params['href'];
     }
     unset($tag_params['only_href']);
     unset($tag_params['remote']);
     if ($tag_params['confirm_text'] == true) {
         if ($tag_params['onclick'] != '') {
             $tag_params['onclick'] = "if (confirm('" . $tag_params['confirm_text'] . "')) { " . $tag_params['onclick'] . " } else { return false; }";
         } else {
             $tag_params['onclick'] = "return confirm('" . $tag_params['confirm_text'] . "');";
         }
     }
     unset($tag_params['confirm_text']);
     if ($tag_params['onclick'] == '') {
         unset($tag_params['onclick']);
     }
     $text = $tag_params['text'];
     unset($tag_params['text']);
     $result = forms()->create_start_tag('a', $tag_params);
     $result .= $text;
     $result .= forms()->create_end_tag('a');
     return $result;
 }