For example: {{{// In controller code: $post = Post::find(1); return compact('post'); In view code: form->create($post); // Echoes a
tag and binds the helper to $post ?> form->text('title'); // Echoes an element, pre-filled with $post's title ?> form->submit('Update'); // Echoes a submit button with the title 'Update' ?> form->end(); // Echoes a
tag & unbinds the form ?> }}}
Inheritance: extends lithium\template\Helper
Esempio n. 1
0
 public function field($name, array $options = array())
 {
     if (isset($this->_binding) and is_numeric($this->_binding->{$name}) and abs($this->_binding->{$name}) <= 1.0E-5) {
         $options['value'] = '0';
     }
     if (!isset($options['wrap'])) {
         $options['wrap'] = array();
     }
     if (!isset($options['wrap']['class'])) {
         $options['wrap']['class'] = '';
     }
     $options['wrap']['class'] .= ' control-group';
     $errors = is_object($this->_binding) ? $this->_binding->errors() : array();
     if (isset($errors[$name])) {
         $options['wrap']['class'] .= ' error';
     }
     # Auto-populate select-box lists from validation rules
     if (isset($options['type']) and $options['type'] == 'select' and !isset($options['list'])) {
         $rules = $this->_binding->rules();
         if (isset($rules[$name])) {
             if (is_array($rules[$name][0])) {
                 $rule_list = $rules[$name];
             } else {
                 $rule_list = array($rules[$name]);
             }
             foreach ($rule_list as $rule) {
                 if ($rule[0] === 'inList' and isset($rule['list'])) {
                     foreach ($rule['list'] as $optval) {
                         $options['list'][$optval] = ucwords($optval);
                     }
                 }
             }
         }
     }
     return parent::field($name, $options);
 }
Esempio n. 2
0
 public function field($name, array $options = array())
 {
     if (is_array($name)) {
         return $this->_fields($name, $options);
     }
     list(, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
     $meta = isset($this->schema) && is_object($this->schema) ? $this->schema->fields($name) : array();
     $defaults = array('label' => null, 'type' => isset($options['list']) ? 'select' : 'text', 'template' => $template, 'wrap' => array('class' => 'control-group'), 'list' => null);
     if (!empty($meta['required'])) {
         $defaults['required'] = true;
     }
     list($options, $field) = $this->_options($defaults, $options);
     if ($this->_binding) {
         $errors = $this->_binding->errors();
         if (isset($errors[$name])) {
             $options['wrap']['class'] .= ' error';
         }
     }
     # Auto-populate select-box lists from validation rules or methods
     if ($options['type'] == 'select' && empty($options['list'])) {
         $options = $this->_autoSelects($name, $options);
     }
     return parent::field($name, $options);
 }
Esempio n. 3
0
 public function testFormCreateWithMoreParamsButSpecifiedAction()
 {
     $request = new Request();
     $request->params = array('controller' => 'mock', 'action' => 'test', 'args' => array('1'));
     $request->persist = array('controller');
     $context = new MockFormRenderer(compact('request'));
     $form = new Form(compact('context'));
     $result = $form->create(null, array('action' => 'radness'));
     $this->assertTags($result, array('form' => array('action' => "{$this->base}mock/radness", 'method' => 'post')));
 }
Esempio n. 4
0
 protected function _init()
 {
     parent::_init();
     $this->config(array('templates' => array('field' => '<div class="control-group">{:label}<div class="controls">{:input}</div></div>', 'label' => '<label for="{:id}" class="control-label"{:options}>{:title}</label>', 'text' => '<input type="text" name="{:name}"{:options} placeholder="{:name}" />', 'textNoPlaceholder' => '<input type="text" name="{:name}"{:options}  />')));
 }
Esempio n. 5
0
	public function radio($name, array $options = array(), array $list = array()) {
		if (empty($list)) {
			if (!isset($options['checked']) && isset($options['value'])) {
				$value = false;
				if ($name && $this->_binding ) {
					$value = $this->_binding->data($name);
				}
				if ($options['value'] == $value)
					$options['checked'] = true;
			}
			return parent::radio($name,$options);
		}
		$out = '';
		foreach ($list as $value => $label) {
			$itemOptions = $options;
			$itemOptions['id'] = $name.'-'.$label;
			$itemOptions['value'] = $value;
			$out .= '<div class="radio">';
			$out .= $this->radio($name, $itemOptions, array());
			$out .= $this->label($itemOptions['id'], $label);
			$out .= '</div>';
		}
		return $out;
	}
Esempio n. 6
0
 public function select($name, $list = array(), array $options = array())
 {
     $defaults = array('multiple' => false, 'hidden' => true);
     $options += $defaults;
     $out = parent::select($name, $list, $options);
     if ($options['multiple'] && $options['hidden']) {
         return $this->hidden($name . '[]', array('value' => '', 'id' => false)) . $out;
     }
     return $out;
 }