<?php echo form::upload($field->name, $field->value, form::attributes($field->extra));
/** * Generates an opening HTML form tag. * * @param string form action attribute * @param array extra attributes * @param array hidden fields to be created immediately after the form tag * @return string */ public static function open($action = NULL, $attr = array(), $hidden = NULL) { // Make sure that the method is always set empty($attr['method']) and $attr['method'] = 'post'; if ($attr['method'] !== 'post' and $attr['method'] !== 'get') { // If the method is invalid, use post $attr['method'] = 'post'; } if ($action === NULL) { // Use the current URL as the default action $action = url::site(Router::$complete_uri); } elseif (strpos($action, '://') === FALSE) { // Make the action URI into a URL $action = url::site($action); } // Set action $attr['action'] = $action; // Only show the CSRF field when form method is POST $hidden_field = $attr['method'] === 'post' ? form::hidden('form_auth_token', csrf::token()) . "\n" : ''; // Form opening tag $form = '<form' . form::attributes($attr) . '>' . "\n" . $hidden_field; // Add hidden fields immediate after opening tag empty($hidden) or $form .= form::hidden($hidden); return $form; }
public function render(&$render_variables, $errors = array()) { $result = parent::render($render_variables, $errors); // Clean attributes $id = $this->_clean_attributes($result['attributes'], 'id'); $buffer = $this->_create_rating($result['attributes']); $result['template']->element = $buffer; $result['template']->attributes = form::attributes($result['attributes']); return (string) $result['template']->render(); }
public function render(&$render_variables, $errors = array()) { // Load base template and attributes $result = parent::render($render_variables, $errors); $result['template']->element = $this->value; $result['attributes'] = $this->_filter_attributes(array('name'), $result['attributes']); if ($result['attributes']) { $result['template']->attributes = form::attributes($result['attributes']); } // Return the resulting output return (string) $result['template']->render(); }
/** * Creates an HTML form select tag with all avaliable timezones * Mash-up of kohana dropdowns and code retrieved from: * http://usphp.com/manual/en/function.timezone-identifiers-list.php on 7/23/2009 * Modified by K Anderson * * TODO: This needs to be refactored to use the kohana html helpers * * @param string|array input name or an array of HTML attributes * @param string option key that should be selected by default * @param string a string to be attached to the end of the attributes * @return string */ public static function dropdown($data, $selected = NULL, $extra = '') { if (!is_array($data)) { $data = array('name' => $data); } else { if (isset($data['options'])) { // Use data options $options = $data['options']; } if (isset($data['selected'])) { // Use data selected $selected = $data['selected']; } } $input = '<select' . form::attributes($data, 'select') . ' ' . $extra . '>' . "\n"; if (empty($selected)) { $selectedzone = date_default_timezone_get(); } else { $selectedzone = $selected; } $input .= self::timezonechoice($selectedzone); $input .= '</select>'; return $input; }
<?php $selected = false; if ($field->value == $field->selected) { $selected = true; } echo form::radio($field->name, $field->value, $selected, form::attributes($field->extra));
/** * This function buils the HTML for a grid, you can choose to render the paging/nav bar * and supply any additional HTML attributes for either the table of the nav div in a array * such that the array looks like: * * array( * 'table' => array ('id' => 'someID', 'class'=> 'gridTable', 'extra' => 'onclick="alert('test');"), * 'div' => array ('style' => 'text-align: center;') * ) * * @return string grid HTML * @param bool $createNavGrid[optional] * @param array $attributes[optional] */ public function render($createNavGrid = true, $attributes = array()) { /** * * THIS SECTION GENERATES HTML FOR A TABLE * */ $html = '<div id="' . $this->gridName . 'AjaxMessageReceiver" style="display:none;"> </div>'; // If the user has not supplied an id then we will gen one for the table if (empty($attributes['table']['id'])) { $attributes['table']['id'] = $this->gridName; } // We need to add a default class to the table $attributes['table']['class'] = empty($attributes['table']['class']) ? 'scroll jqgrid_instance' : $attributes['table']['class'] . ' scroll jqgrid_instance'; // This gets any extra attributes and unsets it so the form helper will not parse it if (!empty($attributes['table']['extra'])) { $extra = $attributes['table']['extra']; unset($attributes['table']['extra']); } else { $extra = ''; } // Build the HTML for the table $html .= '<table' . form::attributes($attributes['table']) . ' ' . $extra . '><tr><td></td></tr></table>' . "\n"; /** * * THIS SECTION GENERATES HTML FOR A NAVIGATION DIV * */ $customNavButtons = array(); $navGrid = array('options' => array(), 'edit' => array(), 'add' => array(), 'del' => array(), 'search' => array(), 'view' => array()); if ($createNavGrid) { // If the user has not supplied an id then we will gen one for the div if (empty($attributes['div']['id'])) { $attributes['div']['id'] = 'pager_' . $attributes['table']['id']; } // We need to add a default class to the div $attributes['div']['class'] = empty($attributes['div']['class']) ? 'scroll' : $attributes['div']['class'] . ' scroll'; // This gets any extra attributes and unsets it so the form helper will not parse it if (!empty($attributes['div']['extra'])) { $extra = $attributes['div']['extra']; unset($attributes['div']['extra']); } else { $extra = ''; } // Build the HTML for the div $html .= '<div' . form::attributes($attributes['div']) . ' ' . $extra . '></div>' . "\n"; // Add the pager div ID to the grid parameters $this->jquery['pager'] = '#' . $attributes['div']['id']; // build the array of navGrid options, setting defaults as we go if (isset($this->jquery['navGrid'])) { $this->jquery['navGrid'] += $navGrid; $navGrid = $this->jquery['navGrid']; unset($this->jquery['navGrid']); } $navOptions = array('edit' => false, 'add' => false, 'del' => false, 'search' => true, 'view' => false); $navGrid['options'] = arr::merge($navOptions, $navGrid['options']); // build an array of navButtons if (!empty($this->jquery['navButton'])) { $customNavButtons = $this->jquery['navButton']; unset($this->jquery['navButton']); } } /** * * THIS SECTION GENERATES JS * */ self::_orderColumns(); $this->jquery['colNames'] = array_values($this->query['columns']); if (!empty($this->query['actions'])) { // Add this column name to the jqgrid colName headers $this->jquery['colNames'][] = '<div style="text-align:center;">' . __('Actions') . '</div>'; // A convience wraper for adding a colModel to jqgrid $colModel =& $this->jquery['colModel'][]; // Accept any custom parameters for the action column if (!empty($this->query['actionsColumn'])) { $colModel = $this->query['actionsColumn']; } // Add a set of non-overridable defaults and save it as the column model $colModel['name'] = 'actions'; $colModel['search'] = false; $colModel['sortable'] = false; $colModel['align'] = 'center'; } jquery::addPlugin('betagrid'); $jqueryGrid = jquery::addQuery('#' . $attributes['table']['id'])->jqGrid($this->jquery); // This has to come after the jquery helper but the above if block for $createNavGrid must come before if ($createNavGrid) { $jqueryNavGrid = $jqueryGrid->navGrid('#' . $attributes['div']['id'], $navGrid['options'], $navGrid['edit'], $navGrid['add'], $navGrid['del'], $navGrid['search']); if (!empty($customNavButtons)) { foreach ($customNavButtons as $customNavButton) { // Replace the keywords with values $clickFunc =& $customNavButton['onClickButton']; if (!empty($clickFunc)) { $clickFunc = str_replace(array('{table_id}', '{pager_id}'), array($attributes['table']['id'], $attributes['div']['id']), $clickFunc); } // Build the JS for a new navButton $jqueryNavGrid->navButtonAdd('#' . $attributes['div']['id'], $customNavButton); } } } // Return the html string return $html; }
if ($grid->get('display_foot')) { echo GRID_TAB . '<tfoot' . form::attributes($grid->foot_attributes) . '>' . PHP_EOL; echo GRID_TAB . GRID_TAB . '<tr>' . PHP_EOL; foreach ($grid->fields as $field) { echo GRID_TAB . GRID_TAB . GRID_TAB . '<td>' . $field->foot . '</td>' . PHP_EOL; } echo GRID_TAB . GRID_TAB . '</tr>' . PHP_EOL; if ($grid->get('extra_row_foot')) { echo GRID_TAB . GRID_TAB . '<tr>' . PHP_EOL; echo GRID_TAB . GRID_TAB . GRID_TAB . $grid->extra_row_foot . PHP_EOL; echo GRID_TAB . GRID_TAB . '</tr>' . PHP_EOL; } echo GRID_TAB . '</tfoot>' . PHP_EOL; } if ($grid->get('display_body')) { echo GRID_TAB . '<tbody' . form::attributes($grid->body_attributes) . '>' . PHP_EOL; } $i = 0; // Now go for the rows foreach ($grid->data as $data_row) { if ($i % 2 == 1) { $class = $grid->css_class_row_B; } else { $class = $grid->css_class_row_A; } $i++; echo GRID_TAB . GRID_TAB . '<tr class="' . $class . '">' . PHP_EOL; foreach ($grid->fields as $field) { if ($field instanceof Actionfield_Core) { $field->set('value', $data_row); } else {
<?php echo form::textarea($field->name, $field->value, form::attributes($field->extra), $field->encode);
/** * Creates an HTML form input tag. Defaults to a text type. * The default behavior is replicated here because we need to disable specialchars which * would only apply if we were not using doctrine * * @param string|array input name or an array of HTML attributes * @param string input value, when using a name * @param string a string to be attached to the end of the attributes * @param boolean encode existing entities * @return string */ public static function input($data, $value = NULL, $extra = '', $double_encode = TRUE) { if (empty($data['type']) || $data['type'] != 'hidden') { // Add the Bluebox defaults (such as css classes) list($data, $value, $extra) = self::_addDefaults(__FUNCTION__, $data, $value, $extra); } // Type and value are required attributes $data += array('type' => 'text', 'value' => $value); return '<input' . form::attributes($data) . ' ' . $extra . ' />'; }
/** * Creates an HTML form label tag. * * @param string|array label "for" name or an array of HTML attributes * @param string label text or HTML * @param string a string to be attached to the end of the attributes * @return string */ public static function label($data = '', $text = '', $extra = '') { if (!is_array($data)) { if (strpos($data, '[') !== NO) { $data = preg_replace('/\\[.*\\]/', '', $data); } $data = empty($data) ? array() : array('for' => $data); } return '<label' . form::attributes($data) . ' ' . $extra . '>' . $text . '</label>'; }
<?php // For every action that we got foreach ($field->action as $action => $value_field) { // Create <a href="URL/action/ID">TEXT</a> $link = '/' . $action . '/' . $field->value->{$value_field}; echo html::anchor($field->url[$action] . $link, $field->text[$action], form::attributes($field->extra), $field->protocol) . ' '; }
<?php $checked = false; // Is this field to be checked? if (is_array($field->checked)) { if (in_array($field->value, $field->checked)) { $checked = true; } } elseif ($field->value == $field->checked) { $checked = true; } echo form::checkbox($field->name . '[]', $field->value, $checked, form::attributes($field->extra));
<?php echo form::password($field->name, $field->value, form::attributes($field->extra));
/** * Creates an HTML form label tag. * * @param string|array label "for" name or an array of HTML attributes * @param string label text or HTML * @param string a string to be attached to the end of the attributes * @return string */ public static function label($data = '', $text = NULL, $extra = '') { if (!is_array($data)) { if (is_string($data)) { // Specify the input this label is for $data = array('for' => $data); } else { // No input specified $data = array(); } } if ($text === NULL and isset($data['for'])) { // Make the text the human-readable input name $text = ucwords(inflector::humanize($data['for'])); } return '<label' . form::attributes($data) . ' ' . $extra . '>' . $text . '</label>'; }
<?php echo form::dropdown($field->name, $field->options, $field->value, form::attributes($field->extra));
<?php echo form::input($field->name, $field->value, form::attributes($field->extra), $field->encode);
public function label($data, $text, $extra = '') { if (!is_array($data)) { $data = array('for' => $data); } if (isset($this->errors[$data['for']]) || isset($this->messages[$data['for']])) { self::add_class($data, 'error'); } if ($this->is_required($data['for'])) { self::add_class($data, 'required'); } return '<label' . form::attributes($data) . ' ' . $extra . '>' . $text . '</label>'; }