input() публичный Метод

public input ( $name, $options = [] )
 public function input($fieldName, $options = array())
 {
     if (isset($options['label']) && (!isset($options['label']['class']) || !empty($options['label']['class']))) {
         $options['label'] = array('class' => 'col-lg-2 control-label', 'text' => $options['label']);
     }
     return parent::input($fieldName, $options);
 }
Пример #2
0
 function input($fieldName, $options = array())
 {
     if (isset($options['type']) && $options['type'] == 'hidden') {
         return parent::input($fieldName, $options);
     }
     return $this->divWrap(parent::input($fieldName, $options));
 }
Пример #3
0
 /**
  * Input redefinition - required class += required span
  * @link http://book.cakephp.org/view/1390/Automagic-Form-Elements
  */
 function input($fieldName, $options = array())
 {
     if (isset($options['class']) && strstr('required', $options['class'])) {
         $options['label'] .= $this->required();
     }
     return parent::input($fieldName, $options) . "\n";
 }
Пример #4
0
	public function input($fieldName, $options = array()) {

		if (!empty($options['type']) and ($options['type'] == 'submit')) {
            if ((!empty($options['label'])) and is_array($options['label'])) {
				$label['class'] = (!empty($label['class']))? 'control-label col-sm-2 '.$options['label']: 'control-label col-sm-2';
				$label['text'] = (!empty($label['text']))? $options['label']['text']: false;
			} else if (!empty($options['label'])) {
				$label['text'] = false;
				$label['class'] = 'control-label col-sm-2';
			}

			if (isset($label)) {
				$options['label'] = $label;
			}
			if (empty($options['class'])) $options['class'] = 'btn btn-danger';
		} else {
			if (!empty($options['class'])) $options['class'] = 'form-control '.$options['class'];
			if ((!empty($options['label'])) and is_array($options['label'])) {
				$options['label']['class'] = (!empty($options['label']['class']))? 'control-label col-sm-2 '.$options['label']['class']: 'control-label col-sm-2';
			} else if (!empty($options['label'])) {
				$label['text'] = $options['label'];
				$label['class'] = 'control-label col-sm-2';
				$options['label'] = $label;
			}
		}

		if (empty($options['between'])) $options['between'] = '<div class="col-sm-10">';
		if (!empty($options['after'])) $options['after'] = $options['after'].'</div></div> ';

		return parent::input($fieldName, $options);
	}
Пример #5
0
 /**
  * Adds Bootstrap-style class name to datetime inputs
  * @param string $fieldName
  * @param array $options
  * @return string
  */
 public function input($fieldName, $options = array())
 {
     if (!isset($options['multiple'])) {
         // TODO : find a way to make select multiple change into multiple checkboxes
         //	$options['multiple'] = 'checkbox';
     }
     if (!isset($options['type'])) {
         $modelKey = $this->model();
         $fieldKey = $this->field();
         $fieldDef = $this->_introspectModel($modelKey, 'fields', $fieldKey);
         if (is_null($fieldDef)) {
             $options['multiple'] = 'checkbox';
         } else {
             if ($fieldDef['type'] == 'datetime') {
                 // Add "input-small" to class attribute
                 if (isset($options['class'])) {
                     $classes = explode(' ', $options['class']);
                     $classes[] = 'input-medium';
                     $options['class'] = implode(' ', $classes);
                 } else {
                     $options['class'] = 'input-medium';
                 }
             }
         }
     } else {
         if ($options['type'] == 'quantity') {
             $options['type'] = 'number';
             $options['pattern'] = '^[0-9]\\d*$';
         }
     }
     return parent::input($fieldName, $options);
 }
Пример #6
0
 function input($fieldName, $options = array())
 {
     if (!empty($this->params['named']) && !empty($this->params['named'][$fieldName])) {
         $options['value'] = $this->params['named'][$fieldName];
     }
     $fieldType = $fieldName;
     $pos = strrpos($fieldType, '.');
     if (!($pos === false)) {
         $fieldType = substr($fieldType, $pos + 1);
     }
     switch ($fieldType) {
         case "file":
         case "movie":
         case "image":
         case "thumbnail":
         case "thumb":
         case "logo":
         case "afbeelding":
         case "foto":
         case "photo":
             $options['type'] = 'file';
             break;
     }
     return parent::input($fieldName, $options);
 }
 public function input($fieldName, $options = array())
 {
     $defaults = array('before' => '', 'between' => '<div class="controls">', 'after' => '</div>', 'format' => array('before', 'label', 'between', 'input', 'error', 'after'), 'class' => $this->formSpan, 'div' => array('class' => 'control-group'), 'error' => array('attributes' => array('class' => 'help-block error', 'wrap' => 'span')), 'help' => '', 'required' => false, 'append' => array(), 'prepend' => array());
     $options = array_merge($defaults, $this->_inputDefaults, $options);
     if (isset($options['type']) && $options['type'] == 'radio') {
         $options['between'] = $options['after'] = '';
     }
     if (isset($options['help'])) {
         $options['after'] = '<p class="help-block">' . $options['help'] . '</p>' . $options['after'];
         unset($options['help']);
     }
     if (isset($options['actions'])) {
         $options['after'] .= '<div class="actions">' . join("\n", $options['actions']) . '</div>';
         unset($options['actions']);
     }
     if (!empty($options['prepend']) && empty($options['append'])) {
         $prepend = is_array($options['prepend']) ? join("\n", $options['prepend']) : '<span class="add-on">' . $options['prepend'] . '</span>';
         $options['between'] .= '<div class="input-prepend">' . $prepend;
         $options['after'] = '</div>' . $options['after'];
         unset($options['prepend']);
     } elseif (!empty($options['append']) && empty($options['prepend'])) {
         $append = is_array($options['append']) ? join("\n", $options['append']) : '<span class="add-on">' . $options['append'] . '</span>';
         $options['between'] .= '<div class="input-append">';
         $options['after'] = $append . '</div>' . $options['after'];
         unset($options['append']);
     } elseif (!empty($options['prepend']) && !empty($options['append'])) {
         $prepend = is_array($options['prepend']) ? join("\n", $options['prepend']) : '<span class="add-on">' . $options['prepend'] . '</span>';
         $append = is_array($options['append']) ? join("\n", $options['append']) : '<span class="add-on">' . $options['append'] . '</span>';
         $options['between'] .= '<div class="input-append input-prepend">' . $prepend;
         $options['after'] = $append . '</div>' . $options['after'];
         unset($options['prepend']);
         unset($options['append']);
     }
     return parent::input($fieldName, $options);
 }
Пример #8
0
 function input($fieldName, $options = array())
 {
     if (ClassRegistry::isKeySet($this->model())) {
         $model =& ClassRegistry::getObject($this->model());
         if ($model->isOrigamiColumn($fieldName)) {
             $type = $model->getOrigamiColumnType($fieldName);
             if (method_exists($this, $type)) {
                 unset($options['type']);
                 // We are specifying the type, so we need to remove any user specified types
                 $out = $this->{$type}($fieldName, $options);
                 // The code is this section is mostly copied from the cake php
                 // FormHelper input method
                 $div = true;
                 $divOptions = array();
                 if (array_key_exists('div', $options)) {
                     $div = $options['div'];
                     unset($options['div']);
                 }
                 if (!empty($div)) {
                     $divOptions['class'] = 'input';
                     $divOptions = $this->addClass($divOptions, $type);
                     if (is_string($div)) {
                         $divOptions['class'] = $div;
                     } elseif (is_array($div)) {
                         $divOptions = array_merge($divOptions, $div);
                     }
                     if (in_array($this->field(), $this->fieldset['validates'])) {
                         $divOptions = $this->addClass($divOptions, 'required');
                     }
                     if (!isset($divOptions['tag'])) {
                         $divOptions['tag'] = 'div';
                     }
                 }
                 if ($type != 'hidden') {
                     $error = null;
                     if (isset($options['error'])) {
                         $error = $options['error'];
                         unset($options['error']);
                     }
                     if ($error !== false) {
                         $errMsg = $this->error($fieldName, $error);
                         if ($errMsg) {
                             $out .= $errMsg;
                             $divOptions = $this->addClass($divOptions, 'error');
                         }
                     }
                 }
                 if (isset($divOptions) && isset($divOptions['tag'])) {
                     $tag = $divOptions['tag'];
                     unset($divOptions['tag']);
                     $out = $this->Html->tag($tag, $out, $divOptions);
                 }
                 // end cake php inputs copy
                 return $out;
             }
         }
     }
     return parent::input($fieldName, $options);
 }
Пример #9
0
 /**
  * create tweet box
  *
  * @param $fieldName
  * @param $options
  *      type: element type (default: textarea)
  *      maxLength:   text max length (default: 140)
  *      counterText: length message
  *      submit: submit button message. if set to false, not create.
  *      jqueryCharCount: path to charCount.js (jquery plugin)
  *      other keys set to input element options.
  */
 public function tweet($fieldName, $options = array())
 {
     $this->setEntity($fieldName);
     $domId = !empty($options['id']) ? $options['id'] : $this->domId($fieldName);
     $default = array('type' => 'textarea', 'maxlength' => 140, 'jqueryCharCount' => '/twitter_kit/js/charCount.js', 'counterText' => __d('twitter_kit', 'Characters left: ', true), 'submit' => __d('twitter_kit', 'Tweet', true));
     $options = am($default, $options);
     $inputOptions = $options;
     unset($inputOptions['jqueryCharCount']);
     unset($inputOptions['counterText']);
     unset($inputOptions['submit']);
     $out = $this->Html->script($options['jqueryCharCount']);
     $out .= $this->Form->input($fieldName, $inputOptions);
     $out .= $this->Js->buffer("\n            \$('#{$domId}').charCount({\n                limit: {$options['maxlength']},\n                counterText: '{$options['counterText']}',\n                exceeded: function(element) {\n                    \$('#{$domId}Submit').attr('disabled', true);\n                },\n                allowed: function(element) {\n                    \$('#{$domId}Submit').removeAttr('disabled');\n                }\n            });\n        ");
     if ($options['submit']) {
         $out .= $this->Form->submit($options['submit'], array('id' => $domId . 'Submit'));
     }
     return $this->output($out);
 }
 public function input($fieldName, $options = array())
 {
     $this->setEntity($fieldName);
     $model = $this->_getModel($this->model());
     $fieldKey = $this->field();
     if (!@$options['type'] && $model->hasMethod('cloudinaryFields') && in_array($fieldKey, $model->cloudinaryFields())) {
         $options['type'] = 'file';
     }
     return parent::input($fieldName, $options);
 }
Пример #11
0
 public function input($fieldName, $options = array())
 {
     $this->setEntity($fieldName);
     $options = $this->_parseOptions($options);
     if ($options['type'] == 'checkbox') {
         $options['format'] = array('before', 'label', 'between', 'input', 'after', 'error');
     } elseif ($options['type'] == 'text' || $options['type'] == 'textarea') {
         $options = array_merge(array('class' => 'input-xxlarge'), $options);
     }
     return parent::input($fieldName, $options);
 }
 public function input($fieldName, $options = array())
 {
     $options += $this->_inputDefaults + array('div' => 'form-field', 'class' => 'input-text medium', 'error' => array('attributes' => array('wrap' => 'small')));
     if ($options['class'] !== 'input-text') {
         $options['class'] .= ' input-text';
     }
     if (!empty($options['error']) && empty($options['error']['attributes']['wrap'])) {
         $options['error']['attributes']['wrap'] = 'small';
     }
     return parent::input($fieldName, $options);
 }
Пример #13
0
 /**
  * Create a input with CKEditor
  *
  * @param string $name - field name
  * @param array $options - input options
  * @return string
  */
 public function editor($fieldName, $options = array())
 {
     $this->Html->script('vendor/ckeditor/ckeditor', array('inline' => false));
     $this->Html->css('/js/vendor/ckeditor/fixes', array('inline' => false));
     $options = array_merge(array('class' => 'ckeditor'), $options);
     //
     // $options['class'] = 'ckeditor '.$options['class'];
     if (isset($options['fullwidth']) && $options['fullwidth']) {
         return '<div class="control-group"><div class="clearfix"></div><div class="shadow text-center">' . $this->textarea($fieldName, $options) . '</div></div>';
     }
     return parent::input($fieldName, $options);
 }
Пример #14
0
 public function input($fieldName, $options = array())
 {
     $fieldNameShort = $fieldName;
     if (strstr($fieldName, '.')) {
         $fullName = explode('.', $fieldName);
         $model = $fullName[0];
         $fieldNameShort = end($fullName);
     }
     $defaults = array('placeholder' => Inflector::humanize($fieldNameShort));
     $options = Set::merge($defaults, $options);
     return parent::input($fieldName, $options);
 }
 public function input($fieldName, $options = array())
 {
     if (isset($options['label']) && is_string($options['label'])) {
         $option['text'] = $options['label'];
         $options['label'] = array_merge($option, $this->_inputDefaults['label']);
     } else {
         if (isset($options['label']['text']) && !isset($options['label']['class'])) {
             $options['label'] = array_merge($options['label'], $this->_inputDefaults['label']);
         }
     }
     return parent::input($fieldName, $options);
 }
Пример #16
0
 function input($fieldName, $options = array())
 {
     if (empty($options['div'])) {
         $options['div'] = array();
     }
     $options['div']['data-role'] = 'fieldcontain';
     if (!empty($options['type']) && $options['type'] == 'checkbox') {
         $options['before'] = '<fieldset data-role="controlgroup">';
         $options['after'] = '</fieldset>';
     }
     return parent::input($fieldName, $options);
 }
Пример #17
0
 public function editor($fieldName, $options = array())
 {
     $options = Hash::merge(['div' => false, 'label' => false], $options);
     $options['class'] = 'rte-ckeditor';
     $options['type'] = 'textarea';
     $this->setEntity($fieldName);
     //$this->Html->scriptStart();
     //$this->Html->scriptEnd();
     $out = parent::input($fieldName, $options);
     $element = $this->_View->element('ckeditor/script');
     return $out;
     // . PHP_EOL . $element;
 }
Пример #18
0
 public function input($fieldName, $options = array())
 {
     if (empty($options['title']) && empty($options['label']) && !empty($options['placeholder']) && empty($options['tooltip'])) {
         $options['tooltip'] = $options['placeholder'];
     }
     if (!empty($options['help'])) {
         $options = $this->_helpText($options);
     }
     if (array_key_exists('tooltip', $options)) {
         $options = $this->_tooltip($options);
     }
     return parent::input($fieldName, $options);
 }
 /**
  * build custom input field
  * @param $name
  * @return string
  */
 public function input($fieldName, $options = array())
 {
     $this->setEntity($fieldName);
     $defaults = array('format' => array('before', 'label', 'between', 'input', 'error', 'after'), 'div' => array('class' => 'control-group'), 'error' => array('attributes' => array('class' => 'help-inline', 'wrap' => 'span')), 'help' => '');
     $options = array_merge($defaults, $options);
     if (!empty($options['help'])) {
         $options['after'] = '<span class="help-block">' . $options['help'] . '</span>' . $options['after'];
     }
     $modelKey = $this->model();
     $fieldKey = $this->field();
     if ($this->_introspectModel($modelKey, 'validates', $fieldKey)) {
         $options['label'] = $this->addClass($options['div'], 'notice');
     }
     return parent::input($fieldName, $options);
 }
Пример #20
0
 public function input($fieldName, $options = array())
 {
     if (isset($options['bootstrap']) && $options['bootstrap'] == false) {
         unset($options['bootstrap']);
         return parent::input($fieldName, $options);
     }
     $model = $this->_getModel($this->model());
     if ($model && is_array($fieldOptions = $model->getFieldProperties($fieldName))) {
         if (!empty($options)) {
             $options = am($fieldOptions, $options);
         } else {
             $options = $fieldOptions;
         }
     }
     return parent::input($fieldName, $options);
 }
Пример #21
0
 public function input($fieldName, $options = array())
 {
     $optionsDefault = array('class' => 'form-control', 'div' => 'form-group');
     $options = array_merge_recursive($optionsDefault, $options);
     if (sizeof($options['div']) > 1) {
         $options['div'] = join(' ', $options['div']);
     }
     if (!isset($options['placeholder'])) {
         $label = isset($options['label']) ? $options['label'] : Inflector::humanize($fieldName);
         $options['placeholder'] = $label;
     }
     if (isset($options['helpText'])) {
         $options['after'] = '<span class="help-block">' . $options['helpText'] . '</span>';
     }
     return parent::input($fieldName, $options);
 }
Пример #22
0
 public function input($fieldName, $options = array())
 {
     $this->setEntity($fieldName);
     $defaultOptions = $this->_parseOptions($options);
     if ($defaultOptions['type'] == 'checkbox') {
         $newDefaultOptions = array('div' => array('class' => 'checkbox'), 'class' => false, 'type' => 'checkbox');
         if (isset($defaultOptions["disabled"]) && $defaultOptions['disabled'] == 'disabled') {
             $newDefaultOptions['div']['class'] .= ' disabled';
         }
         $options = array_merge($newDefaultOptions, $options);
     }
     if ($defaultOptions['type'] == 'radio') {
         $defaultOptions = array('div' => array('class' => 'radio'), 'separator' => '</div><div class="radio">', 'class' => false, 'legend' => false);
         $options = array_merge($defaultOptions, $options);
     }
     return parent::input($fieldName, $options);
 }
Пример #23
0
 public function input($fieldName, $options = array())
 {
     if (!isset($options['type']) && !isset($options['options'])) {
         $modelKey = $this->model();
         if (preg_match('/^enum\\((.+)\\)$/ui', $this->fieldset[$modelKey]['fields'][$fieldName]['type'], $m)) {
             $match = trim($m[1]);
             $qOpen = substr($match, 0, 1);
             $qClose = substr($match, -1);
             $delimiter = $qOpen . ',' . $qClose;
             preg_match('/^' . $qOpen . '(.+)' . $qClose . '$/u', $match, $m);
             $_options = explode($delimiter, $m[1]);
             $options['type'] = 'select';
             $options['options'] = array_combine($_options, $_options);
         }
     }
     return parent::input($fieldName, $options);
 }
Пример #24
0
 /**
  * Overwrite FormHelper::input()
  *
  * - Generates a form input element complete with label and wrapper div
  *
  * ### Options
  *
  * See each field type method for more information. Any options that are part of
  * $attributes or $options for the different **type** methods can be included in `$options` for input().i
  * Additionally, any unknown keys that are not in the list below, or part of the selected type's options
  * will be treated as a regular html attribute for the generated input.
  *
  * - `type` - Force the type of widget you want. e.g. `type => 'select'`
  * - `label` - Either a string label, or an array of options for the label. See FormHelper::label().
  * - `div` - Either `false` to disable the div, or an array of options for the div.
  *	See HtmlHelper::div() for more options.
  * - `options` - For widgets that take options e.g. radio, select.
  * - `error` - Control the error message that is produced. Set to `false` to disable any kind of error reporting (field
  *    error and error messages).
  * - `errorMessage` - Boolean to control rendering error messages (field error will still occur).
  * - `empty` - String or boolean to enable empty select box options.
  * - `before` - Content to place before the label + input.
  * - `after` - Content to place after the label + input.
  * - `between` - Content to place between the label + input.
  * - `format` - Format template for element order. Any element that is not in the array, will not be in the output.
  *	- Default input format order: array('before', 'label', 'between', 'input', 'after', 'error')
  *	- Default checkbox format order: array('before', 'input', 'between', 'label', 'after', 'error')
  *	- Hidden input will not be formatted
  *	- Radio buttons cannot have the order of input and label elements controlled with these settings.
  *
  * Added options
  * - `wrapInput` - Either `false` to disable the div wrapping input, or an array of options for the div.
  *	See HtmlHelper::div() for more options.
  * - `checkboxDiv` - Wrap input checkbox tag's class.
  * - `beforeInput` - Content to place before the input.
  * - `afterInput` - Content to place after the input.
  * - `errorClass` - Wrap input tag's error message class.
  *
  * @param string $fieldName This should be "Modelname.fieldname"
  * @param array $options Each type of input takes different options.
  * @return string Completed form widget.
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#creating-form-elements
  */
 public function input($fieldName, $options = array())
 {
     $this->_fieldName = $fieldName;
     $default = array('error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-block text-danger')), 'wrapInput' => array('tag' => 'div'), 'checkboxDiv' => 'checkbox', 'beforeInput' => '', 'afterInput' => '', 'errorClass' => 'has-error error');
     if (isset($options['label']) && is_string($options['label'])) {
         $options['label'] = array('text' => $options['label']);
     }
     $options = Hash::merge($default, $this->_inputDefaults, $options);
     $this->_inputOptions = $options;
     $options['error'] = false;
     if (isset($options['wrapInput'])) {
         unset($options['wrapInput']);
     }
     if (isset($options['checkboxDiv'])) {
         unset($options['checkboxDiv']);
     }
     if (isset($options['beforeInput'])) {
         unset($options['beforeInput']);
     }
     if (isset($options['afterInput'])) {
         unset($options['afterInput']);
     }
     if (isset($options['errorClass'])) {
         unset($options['errorClass']);
     }
     $inputDefaults = $this->_inputDefaults;
     $this->_inputDefaults = array();
     $html = parent::input($fieldName, $options);
     $this->_inputDefaults = $inputDefaults;
     if ($this->_inputType === 'checkbox') {
         if (isset($options['before'])) {
             $html = str_replace($options['before'], '%before%', $html);
         }
         $regex = '/(<label.*?>)(.*?<\\/label>)/';
         if (preg_match($regex, $html, $label)) {
             $label = str_replace('$', '\\$', $label);
             $html = preg_replace($regex, '', $html);
             $html = preg_replace('/(<input type="checkbox".*?>)/', $label[1] . '$1 ' . $label[2], $html);
         }
         if (isset($options['before'])) {
             $html = str_replace('%before%', $options['before'], $html);
         }
     }
     return $html;
 }
Пример #25
0
 /**
  * Add divs and classes necessary for bootstrap
  *
  */
 public function input($fieldName, $params = array())
 {
     $defaults = array('div' => array('class' => 'control-group'), 'label' => array('class' => 'control-label'), 'between' => '<div class="controls">', 'format' => array('before', 'label', 'between', 'input', 'error', 'after'));
     $options = Set::merge($defaults, $params);
     $prepend = isset($options['bootstrap-prepend']) && is_string($options['bootstrap-prepend']) ? " input-prepend" : "";
     $append = isset($options['bootstrap-append']) && is_string($options['bootstrap-append']) ? " input-append" : "";
     if ($prepend || $append) {
         if (!isset($options['before'])) {
             $options['before'] = '';
         }
         if (!isset($options['between'])) {
             $options['between'] = '';
         }
         if (!isset($options['after'])) {
             $options['after'] = '';
         }
         $options['before'] .= '<div class="' . trim($prepend . $append) . '">';
         if ($prepend) {
             $options['between'] .= '<span class="add-on">' . $options['bootstrap-prepend'] . '</span>';
         }
         if ($append) {
             $options['after'] .= '<span class="add-on">' . $options['bootstrap-append'] . '</span>';
         }
         $options['after'] .= '</div>';
         unset($options['bootstrap-prepend']);
         unset($options['bootstrap-append']);
     }
     if (!isset($options['after'])) {
         $options['after'] = '';
     }
     $options['after'] .= '</div>';
     if (isset($options['label']) && is_string($options['label'])) {
         $options['label'] = array('class' => 'control-label', 'text' => $options['label']);
     }
     if (isset($options['div']) && $options['div'] === false) {
         unset($options['between'], $options['after']);
     }
     // if ($append) {
     // 	prd(compact('fieldName', 'options', 'params', 'default'));
     // }
     return parent::input($fieldName, $options);
 }
Пример #26
0
 function input($fieldName, $options = array())
 {
     $this->setEntity($fieldName);
     $modelKey = $this->model();
     $fieldKey = $this->field();
     if (!isset($this->fieldset[$modelKey])) {
         $this->_introspectModel($modelKey);
     }
     if ((!isset($options['type']) || $options['type'] == 'select') && !isset($options['options'])) {
         if (isset($this->fieldset[$modelKey]['fields'][$fieldKey])) {
             $type = $this->fieldset[$modelKey]['fields'][$fieldKey]['type'];
             if (substr($type, 0, 4) == 'enum') {
                 $arr = explode('\'', $type);
                 $enumValues = array();
                 foreach ($arr as $value) {
                     if ($value != 'enum(' && $value != ',' && $value != ')') {
                         $options['options'][$value] = __($value, true);
                     }
                 }
             }
         }
     }
     return parent::input($fieldName, $options);
 }
Пример #27
0
 /**
  * インプットタグを作成する
  * 
  * @param type $fieldName
  * @param type $options
  * @return string
  */
 public function input($fieldName, $options = array())
 {
     $options['div'] = isset($options['div']) ? $options['div'] : false;
     $options['label'] = isset($options['label']) ? $options['label'] : false;
     $options['error'] = isset($options['error']) ? $options['error'] : false;
     $options['legend'] = isset($options['legend']) ? $options['legend'] : false;
     $options['refer'] = isset($options['refer']) ? $options['refer'] : true;
     $arrTmp = explode('.', $fieldName);
     if (isset($arrTmp[1]) && $options['refer'] === true) {
         $model = ClassRegistry::init(array_shift($arrTmp));
         $options = am($model->getFormParams(join('.', $arrTmp)), $options);
     } else {
         if ($this->_model instanceof Model && $options['refer'] === true) {
             $options = am($this->_model->getFormParams($fieldName), $options);
         }
     }
     unset($options['refer']);
     if (in_array($options['type'], array('date', 'time', 'datetime'))) {
         $options['monthNames'] = isset($options['monthNames']) ? $options['monthNames'] : false;
         $options['timeFormat'] = isset($options['timeFormat']) ? $options['timeFormat'] : 24;
         $options['dateFormat'] = isset($options['dateFormat']) ? $options['dateFormat'] : 'YMD';
     }
     return parent::input($fieldName, $options);
 }
 public function input($fieldName, $options = array())
 {
     $options = array_merge(array('format' => array('before', 'label', 'between', 'input', 'error', 'after')), $this->_inputDefaults, $options);
     $this->_Opts[$fieldName] = $options;
     $type = $this->_extractOption('type', $options);
     $options = $this->_getType($fieldName, $options);
     $hidden = null;
     if ('hidden' === $options['type']) {
         $options['div'] = false;
         $options['label'] = false;
     } else {
         $options = $this->uneditable($fieldName, $options, true);
         $options = $this->addon($fieldName, $options, true);
         $options = $this->textarea($fieldName, $options, true);
         $options = $this->checkbox($fieldName, $options, true);
         $options = $this->_controlGroupStates($fieldName, $options);
         $options = $this->_buildAfter($options);
         $hidden = $this->_hidden($fieldName, $options);
         if ($hidden) {
             $options['hiddenField'] = false;
         }
     }
     if (is_null($type) && empty($this->_Opts[$fieldName]['type'])) {
         unset($options['type']);
     }
     $disabled = $this->_extractOption('disabled', $options, false);
     if ($disabled) {
         $options = $this->addClass($options, 'disabled');
     }
     $div = $this->_extractOption('div', $options);
     $options['div'] = false;
     $before = $this->_extractOption('before', $options);
     $options['before'] = null;
     $label = $this->_extractOption('label', $options);
     if (false !== $label) {
         if (!is_array($label)) {
             $label = array('text' => $label);
         }
         if (false !== $div) {
             $class = $this->_extractOption('class', $label, 'control-label');
             $label = $this->addClass($label, $class);
         }
         $text = $label['text'];
         unset($label['text']);
         $label = $this->label($fieldName, $text, $label);
     }
     $options['label'] = false;
     $between = $this->_extractOption('between', $options);
     $options['between'] = null;
     $input = parent::input($fieldName, $options);
     $divControls = $this->_extractOption('divControls', $options, self::CLASS_INPUTS);
     $input = $hidden . (false === $div ? $input : $this->Html->div($divControls, $input));
     $out = $before . $label . $between . $input;
     return false === $div ? $out : $this->Html->div($div, $out);
 }
Пример #29
0
 public function input($fieldName, $options = array())
 {
     $this->setEntity($fieldName);
     $temp_options = $this->_parseOptions($options);
     $field_array = $this->entity();
     $currentModel = $this->_getModel($field_array[0]);
     $field = array_pop($field_array);
     //put placeholders
     if (isset($currentModel->placeholder) && !isset($options['placeholder'])) {
         if (isset($currentModel->placeholder[$field])) {
             $options['placeholder'] = __($currentModel->placeholder[$field]);
         }
     }
     //put tooltips
     if (isset($currentModel->tooltips)) {
         if (isset($currentModel->tooltips[$field])) {
             if (isset($options['label']) && $options['label'] === false) {
                 $options['label'] = false;
             } else {
                 if (!empty($options['label'])) {
                     $options['label'] = $options['label'] . '<span class="btn btn-xs btn-link cakeui-tooltip" data-toggle="tooltip" data-placement="right" title="' . __($currentModel->tooltips[$field]) . '">?</button>';
                 } else {
                     $label = __(Inflector::humanize(Inflector::underscore($field)));
                     $options['label'] = $label . '<button type="button" class="btn btn-xs btn-link cakeui-tooltip" data-toggle="tooltip" data-placement="right" title="' . __($currentModel->tooltips[$field]) . '">?</button>';
                 }
             }
         }
     }
     //put mask
     if (isset($currentModel->mask) && !isset($mask['data-inputmask'])) {
         if (isset($currentModel->mask[$field])) {
             if (is_array($currentModel->mask[$field])) {
                 if (!isset($options['class'])) {
                     $options['class'] = null;
                 }
                 $options['class'] .= 'form-control ' . $currentModel->mask[$field]['class'];
             } else {
                 $options['data-inputmask'] = $currentModel->mask[$field];
             }
         }
     }
     if ($this->isFieldError($fieldName)) {
         if (isset($options['div'])) {
             if (is_array($options['div'])) {
                 if (!isset($options['div']['class'])) {
                     $options['div']['class'] = ' has-error has-feedback';
                 } else {
                     $options['div']['class'] .= ' has-error has-feedback';
                 }
             } else {
                 $options['div'] .= ' has-error has-feedback';
             }
         } else {
             $options['div']['class'] = ' has-error has-feedback';
         }
         if (!isset($options['after'])) {
             $options['after'] = null;
         }
         if ($temp_options['type'] == 'text' || $temp_options['type'] == 'password' || $temp_options['type'] == 'email') {
             if ($temp_options['label'] == false) {
                 $options['after'] .= '<span class="glyphicon glyphicon-remove form-control-feedback no-label"></span>';
             } else {
                 $options['after'] .= '<span class="glyphicon glyphicon-remove form-control-feedback"></span>';
             }
         }
     }
     if (isset($options['multiple']) && $options['multiple'] === 'checkbox') {
         $options['class'] = null;
         $options['between'] = '<div class="checkbox-container">';
         $options['after'] = '</div>';
     }
     $options = $this->_parseOptions($options);
     if ($options['type'] == 'checkbox') {
         if (empty($options['div']['class'])) {
             $options['div']['class'] = 'checkbox';
         } else {
             $options['div']['class'] .= ' checkbox';
         }
     }
     return parent::input($fieldName, $options);
 }
Пример #30
0
 /**
  * Takes the array of options and will apply the append or prepend bits
  * from the options and returns the input string.
  *
  * @param mixed $input
  * @param string $type
  * @access public
  * @return string
  */
 public function _combineInput($options)
 {
     $combine_markup = array("append" => "", "prepend" => "");
     $input = "";
     if (isset($options["input"])) {
         $input = $options["input"];
     } else {
         $opt = array("div" => false, "label" => false, "error" => false);
         foreach ($options as $key => $value) {
             if (!in_array($key, $this->__dontSendToFormHelper)) {
                 if ($key !== 'type' || !empty($value)) {
                     $opt[$key] = $value;
                 }
             }
         }
         $input = parent::input($options["field"], $opt);
         if (isset($options["checkbox_label"])) {
             $input = $this->label($options["field"], $input . ' ' . $options["checkbox_label"], array('class' => 'checkbox'));
         }
     }
     foreach (array_keys($combine_markup) as $combine) {
         if (isset($options[$combine]) && !empty($options[$combine])) {
             $_tag = "span";
             if (strpos($options[$combine], "button") !== false) {
                 $_tag = false;
             }
             if (strpos($options[$combine], "input") !== false) {
                 $_tag = "label";
             }
             if ($_tag) {
                 $combine_markup[$combine] = $this->Html->tag($_tag, $options[$combine], array("class" => "add-on"));
             } else {
                 $combine_markup[$combine] = $options[$combine];
             }
         }
     }
     $_class = "";
     if (!empty($combine_markup["append"])) {
         $input = $input . $combine_markup["append"];
         $_class .= " input-append";
     }
     if (!empty($combine_markup["prepend"])) {
         $input = $combine_markup["prepend"] . $input;
         $_class .= " input-prepend";
     }
     if (!empty($combine_markup["append"]) || !empty($combine_markup["prepend"])) {
         $input = $this->Html->tag("div", $input, array("class" => trim($_class)));
     }
     return $input;
 }