function smarty_function_password($params, &$smarty) { if (!isset($params['password'])) { $params['password'] = true; } return forms()->create_input_text($params); }
function test_forms_from_model() { $manager = minim('orm')->register('dummy'); $manager->int('foo')->text('bar'); $this->assertEqual(2, count($manager->_fields), "Manager should have 2 fields"); $form = forms()->from_model('dummy'); $this->assertEqual(2, count($form->_fields), "Form should have 2 fields"); }
function smarty_block_select($params, $content, &$smarty, &$repeat) { if (!$repeat) { if (isset($content)) { return forms()->create_input_select($params) . $content . forms()->create_end_tag('select'); } } }
function smarty_block_form($params, $content, &$smarty, &$repeat) { if (!$repeat) { if (isset($content)) { return forms()->create_form_start($params) . $content . forms()->create_form_end(); } } }
function smarty_block_label($params, $content, &$smarty, &$repeat) { if (!$repeat) { if (isset($content)) { $params['content'] = $content; return forms()->create_label_for_input($params); } } }
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>'; } } }
function smarty_function_textbox($params, &$smarty) { return forms()->create_input_text($params); }
function smarty_function_hidden($params, &$smarty) { return forms()->create_input_hidden($params); }
/** * 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; }
<?php /** * Pseudo classes for working with forms * * @see docs/plugins/forms.md */ namespace CssCrush; Plugin::register('forms', array('enable' => function ($process) { foreach (forms() as $name => $handler) { if (is_array($handler)) { $type = $handler['type']; $handler = $handler['handler']; } $process->addSelectorAlias($name, $handler, $type); } })); function forms() { return array('input' => array('type' => 'splat', 'handler' => 'input[type=#(text)]'), 'checkbox' => 'input[type="checkbox"]', 'radio' => 'input[type="radio"]', 'file' => 'input[type="file"]', 'image' => 'input[type="image"]', 'password' => 'input[type="password"]', 'submit' => 'input[type="submit"]', 'text' => 'input[type="text"]'); }
<?php /* Chen Qiu, CSE 154 Section AB, Homework 5, 10/29/2014 This page searches for all the films with the actor the user is searching sorted by year descending, breaking ties by movie title ascending. */ $first = $_GET["firstname"]; $last = $_GET["lastname"]; include "common.php"; $db = new PDO("mysql:dbname=imdb;host=localhost;", "chenq9", "9XcmbstwvP"); $id_rows = search($first, $last, $db); if ($id_rows->rowCount() > 0) { $id = $id_rows->fetch()["id"]; $rows = $db->query("SELECT name, year FROM movies JOIN roles ON movie_id = id WHERE actor_id = {$id} ORDER BY year DESC, name ASC"); $caption = "All Films"; show_table($rows, $first, $last, $caption); } else { // Actor Not Found. ?> <p>Actor <?php echo "{$first} {$last}"; ?> not found.</P> <?php } forms(); footer();
function smarty_function_options($params, &$smarty) { return forms()->create_input_options($params); }
function smarty_function_submit($params, &$smarty) { return forms()->create_input_submit($params); }
function smarty_function_checkbox($params, &$smarty) { return forms()->create_input_checkbox($params); }
function smarty_function_link($params, &$smarty) { return forms()->create_link($params); }