Example #1
0
/**
 * Renders a submit and cancel button
 *
 * @param Pieform  $form    The form to render the element for
 * @param array    $element The element to render
 * @return string           The HTML for the element
 */
function pieform_element_submitcancel(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['value']) || !is_array($element['value']) || count($element['value']) != 2) {
        throw new PieformException('The submitcancel element "' . $element['name'] . '" must have a two element array for its value');
    }
    $form->include_plugin('element', 'submit');
    $form->include_plugin('element', 'cancel');
    $submitelement = $element;
    $submitelement['class'] = isset($submitelement['class']) ? $submitelement['class'] . ' submit' : 'submit';
    $submitelement['value'] = $element['value'][0];
    $cancelelement = $element;
    $cancelelement['class'] = isset($cancelelement['class']) ? $cancelelement['class'] . ' cancel' : 'cancel';
    $cancelelement['value'] = $element['value'][1];
    if (isset($element['confirm']) && isset($element['confirm'][0])) {
        $submitelement['confirm'] = $element['confirm'][0];
    } else {
        unset($submitelement['confirm']);
    }
    if (isset($element['confirm']) && isset($element['confirm'][1])) {
        $cancelelement['confirm'] = $element['confirm'][1];
    } else {
        unset($cancelelement['confirm']);
    }
    return pieform_element_submit($form, $submitelement) . ' ' . pieform_element_cancel($form, $cancelelement);
}
Example #2
0
/**
 * Renders a submit and cancel button
 *
 * @param array    $element The element to render
 * @param Pieform  $form    The form to render the element for
 * @return string           The HTML for the element
 */
function pieform_element_cancelbackcreate(Pieform $form, $element)
{
    $form->include_plugin('element', 'submit');
    $form->include_plugin('element', 'cancel');
    $cancelelement = $element;
    $cancelelement['value'] = $element['value'][0];
    $backelement = $element;
    $backelement['name'] = 'back';
    $backelement['id'] = 'back';
    $backelement['value'] = $element['value'][1];
    $submitelement = $element;
    $submitelement['value'] = $element['value'][2];
    if (isset($element['confirm']) && isset($element['confirm'][0])) {
        $cancelelement['confirm'] = $element['confirm'][0];
    } else {
        unset($cancelelement['confirm']);
    }
    if (isset($element['confirm']) && isset($element['confirm'][1])) {
        $backelement['confirm'] = $element['confirm'][1];
    } else {
        unset($backelement['confirm']);
    }
    if (isset($element['confirm']) && isset($element['confirm'][2])) {
        $submitelement['confirm'] = $element['confirm'][2];
    } else {
        unset($submitelement['confirm']);
    }
    return pieform_element_cancel($form, $cancelelement) . ' ' . pieform_element_submit($form, $backelement) . ' ' . pieform_element_submit($form, $submitelement);
}
Example #3
0
/**
 * Renders a submit and cancel button
 *
 * @param Pieform  $form    The form to render the element for
 * @param array    $element The element to render
 * @return string           The HTML for the element
 */
function pieform_element_submitcancel(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['value']) || !is_array($element['value']) || count($element['value']) != 2) {
        throw new PieformException('The submitcancel element "' . $element['name'] . '" must have a two element array for its value');
    }
    $form->include_plugin('element', 'button');
    $form->include_plugin('element', 'cancel');
    // first try for string indices
    $plugins = array('button', 'cancel');
    $elems = '';
    foreach ($element['value'] as $key => $value) {
        if (!is_numeric($key) && in_array($key, $plugins)) {
            $function = 'pieform_element_' . $key;
            if (function_exists($function)) {
                $item = $element;
                $item['class'] = isset($element['class']) ? $element['class'] . ' ' . $key : $key;
                $item['usebuttontag'] = $key == 'button' ? true : false;
                $item['value'] = $element['value'][$key];
                if (isset($element['confirm']) && isset($element['confirm'][$key])) {
                    $item['confirm'] = $element['confirm'][$key];
                } else {
                    unset($item['confirm']);
                }
                $elems .= $function($form, $item);
                $elems .= ' ';
            }
        }
    }
    if (!empty($elems)) {
        return $elems;
    } else {
        if (isset($element['value'][0]) && isset($element['value'][1])) {
            // ensure default numeric indices exist
            $submitelement = $element;
            $submitelement['class'] = isset($submitelement['class']) ? $submitelement['class'] . ' submit' : 'submit';
            $submitelement['value'] = $element['value'][0];
            $submitelement['usebuttontag'] = true;
            $cancelelement = $element;
            $cancelelement['class'] = isset($cancelelement['class']) ? $cancelelement['class'] . ' cancel' : 'cancel';
            $cancelelement['value'] = $element['value'][1];
            if (isset($element['confirm']) && isset($element['confirm'][0])) {
                $submitelement['confirm'] = $element['confirm'][0];
            } else {
                unset($submitelement['confirm']);
            }
            if (isset($element['confirm']) && isset($element['confirm'][1])) {
                $cancelelement['confirm'] = $element['confirm'][1];
            } else {
                unset($cancelelement['confirm']);
            }
            return pieform_element_button($form, $submitelement) . ' ' . pieform_element_cancel($form, $cancelelement);
        }
    }
}