Example #1
0
function button_to($name, $url = '', array $args = array())
{
    $params = array();
    if (is_array($name)) {
        $params = $name;
    } elseif (is_array($url)) {
        $params['action'] = (string) $name;
    } elseif (!isset($params['text'])) {
        $params['text'] = $name;
    }
    if (is_string($name) && is_array($url)) {
        $params = array_merge($url, $params);
    } elseif (!isset($params['action'])) {
        $params['action'] = $url;
    }
    $props = array('type' => FALSE, 'action' => '', 'method' => 'POST', 'remote' => FALSE, 'params' => FALSE, 'confirm' => FALSE, 'disabled' => FALSE, 'disable_with' => '');
    $params = array_merge($props, $params, array_intersect_key($args, $props));
    $args = array_diff_key($args, array_intersect_key($args, $props));
    $button = tag('input', array_merge(array('type' => 'submit', 'value' => $params['text'], 'disabled' => $params['disabled'], 'data-disable-with' => $params['disable_with'] ?: FALSE), $args));
    $extra = '';
    if ($params['method'] != 'POST') {
        $extra = tag('input', array('type' => 'hidden', 'name' => '_method', 'value' => strtolower($params['method'])));
    }
    $extra .= tag('input', array('type' => 'hidden', 'name' => '_token', 'value' => \Labourer\Web\Session::token()));
    return tag('form', array('class' => 'button-to', 'action' => $params['action'], 'method' => 'post', 'data-type' => $params['type'] ?: FALSE, 'data-confirm' => $params['confirm'] ?: FALSE, 'data-remote' => $params['remote'] ? 'true' : FALSE, 'data-params' => $params['params'] ? http_build_query($params['params']) : FALSE), "<div>{$extra}{$button}</div>");
}
Example #2
0
function csrf_meta_tag()
{
    return \Labourer\Web\Html::meta('csrf-token', \Labourer\Web\Session::token());
}