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

### Options: - type Form method defaults to autodetecting based on the form context. If the form context's isCreate() method returns false, a PUT request will be done. - method Set the form's method attribute explicitly. - action The controller action the form submits to, (optional). Use this option if you don't need to change the controller from the current request's controller. Deprecated since 3.2, use url. - url The URL the form submits to. Can be a string or a URL array. If you use 'url' you should leave 'action' undefined. - encoding Set the accept-charset encoding for the form. Defaults to Configure::read('App.encoding') - enctype Set the form encoding explicitly. By default type => file will set enctype to multipart/form-data. - templates The templates you want to use for this form. Any templates will be merged on top of the already loaded templates. This option can either be a filename in /config that contains the templates you want to load, or an array of templates to use. - context Additional options for the context class. For example the EntityContext accepts a 'table' option that allows you to set the specific Table class the form should be based on. - idPrefix Prefix for generated ID attributes. - templateVars Provide template variables for the formStart template.
public create ( mixed $model = null, array $options = [] ) : string
$model mixed The context for which the form is being defined. Can be an ORM entity, ORM resultset, or an array of meta data. You can use false or null to make a model-less form.
$options array An array of html attributes and options.
Результат string An formatted opening FORM tag.
 public function create($model = null, array $options = [])
 {
     $options += ['role' => 'form'];
     if (isset($options['class']) and $options['class'] == 'form-horizontal') {
         $options['templates'] = $this->templates_horizontal;
     }
     return parent::create($model, $options);
 }
Пример #2
0
 /**
  * @return void
  */
 public function testFormInput()
 {
     $Form = new FormHelper(new View());
     $entity = $this->Table->newEntity();
     $Form->create($entity);
     $x = $Form->input('year_of_birth', ['type' => 'year']);
     $this->assertContains('<select name="year_of_birth[year]" type="year"', $x);
     // <div class="input number"><label for="year-of-birth">Year Of Birth</label><input type="number" name="year_of_birth" id="year-of-birth"/></div>
 }
 /**
  * Override
  *
  * @param mixed $model The context for which the form is being defined.
  * @param array $options An array of html attributes and options.
  * @return string
  */
 public function create($model = null, array $options = [])
 {
     $options[] = 'novalidate';
     $this->_isHorizontal = false;
     if (isset($options['horizontal']) && $options['horizontal'] === true) {
         $this->_isHorizontal = true;
         $this->templates($this->_horizontalTemplates);
         $options = $this->addClass($options, 'form-horizontal');
     }
     return parent::create($model, $options);
 }
Пример #4
0
 /**
  * Returns an HTML FORM element.
  *
  * @param mixed $model The context for which the form is being defined. Can
  *   be an ORM entity, ORM resultset, or an array of meta data. You can use false or null
  *   to make a model-less form.
  * @param array $options An array of html attributes and options.
  * @return string An formatted opening FORM tag.
  */
 public function create($model = null, array $options = [])
 {
     if (isset($options['horizontal'])) {
         if ($options['horizontal'] === true) {
             $options['horizontal'] = 'horizontal';
         }
         $options['align'] = $options['horizontal'];
         unset($options['horizontal']);
         trigger_error('The `horizontal` option is deprecated. Use `align` instead.');
     }
     $options += ['class' => null, 'role' => 'form', 'align' => null, 'templates' => []];
     return parent::create($model, $this->_formAlignment($options));
 }
Пример #5
0
 /**
  * Returns an HTML FORM element.
  *
  * @param mixed $model The context for which the form is being defined. Can
  *   be an ORM entity, ORM resultset, or an array of meta data. You can use false or null
  *   to make a model-less form.
  * @param array $options An array of html attributes and options.
  * @return string An formatted opening FORM tag.
  */
 public function create($model = null, array $options = [])
 {
     $options += ['role' => 'form', 'horizontal' => $this->checkClasses('form-horizontal', $options), 'templates' => []];
     if (!empty($options['horizontal'])) {
         $options = $this->injectClasses('form-horizontal', $options);
         $options['horizontal'] = (array) $options['horizontal'];
         $options['horizontal'] += ['left' => 'col-md-2', 'right' => 'col-md-10', 'combined' => 'col-md-offset-2 col-md-10'];
         if (strpos($options['horizontal']['left'], 'control-label') === false) {
             $options['horizontal']['left'] = 'control-label ' . $options['horizontal']['left'];
         }
         $options['templates'] += ['label' => '<label class="' . $options['horizontal']['left'] . '"{{attrs}}>{{text}}</label>', 'formGroup' => '{{label}}<div class="' . $options['horizontal']['right'] . '">{{input}}</div>', 'checkboxFormGroup' => '<div class="' . $options['horizontal']['combined'] . '">' . '<div class="checkbox">{{label}}</div></div>'];
     }
     unset($options['horizontal']);
     return parent::create($model, $options);
 }
Пример #6
0
 /**
  * Create html form.
  *
  * @param string|null $model
  * @param array $options
  * @return string
  */
 public function create($model = null, array $options = [])
 {
     $options += ['process' => false, 'jsForm' => false];
     $options = $this->addClass($options, 'un-form');
     $isProcess = $options['process'];
     if ($isProcess != false) {
         $_options = ['url' => ['plugin' => $this->request->param('plugin'), 'controller' => $this->request->param('controller'), 'action' => 'process']];
         $options['jsForm'] = true;
         $options = Hash::merge($_options, $options);
     }
     $isJsForm = $options['jsForm'];
     if ($isJsForm) {
         $this->_isJsForm = true;
         $options = $this->addClass($options, 'jsForm');
     }
     unset($options['process']);
     unset($options['jsForm']);
     return parent::create($model, $options);
 }
Пример #7
0
 /**
  * Overwrite to allow FormConfig Configure settings to be applied.
  *
  * @param mixed $model The context for which the form is being defined. Can
  *   be an ORM entity, ORM resultset, or an array of meta data. You can use false or null
  *   to make a model-less form.
  * @param array $options An array of html attributes and options.
  * @return string An formatted opening FORM tag.
  */
 public function create($model = null, array $options = [])
 {
     $defaults = ['novalidate' => $this->_defaultConfig['novalidate']];
     $options += $defaults;
     return parent::create($model, $options);
 }
 /**
  *
  * Create a Twitter Bootstrap like form.
  *
  * New options available:
  * 	- horizontal: boolean, specify if the form is horizontal
  * 	- inline: boolean, specify if the form is inline
  * 	- search: boolean, specify if the form is a search form
  *
  * Unusable options:
  * 	- inputDefaults
  *
  * @param String $model The model corresponding to the form
  * @param $options array Options to customize the form
  *
  * @return string HTML tags corresponding to the openning of the form
  *
  **/
 public function create($model = null, array $options = array())
 {
     if (isset($options['cols'])) {
         $this->colSize = $options['cols'];
         unset($options['cols']);
     } else {
         $this->colSize = $this->_defaultColumnSize;
     }
     $this->horizontal = $this->_extractOption('horizontal', $options, false);
     unset($options['horizontal']);
     $this->search = $this->_extractOption('search', $options, false);
     unset($options['search']);
     $this->inline = $this->_extractOption('inline', $options, false);
     unset($options['inline']);
     if ($this->horizontal) {
         $options = $this->addClass($options, 'form-horizontal');
     } else {
         if ($this->inline) {
             $options = $this->addClass($options, 'form-inline');
         }
     }
     if ($this->search) {
         $options = $this->addClass($options, 'form-search');
     }
     $options['role'] = 'form';
     return parent::create($model, $options);
 }
 /**
  * 
  * Create a Twitter Bootstrap like form. 
  * 
  * New options available:
  * 	- horizontal: boolean, specify if the form is horizontal
  * 	- inline: boolean, specify if the form is inline
  * 	- search: boolean, specify if the form is a search form
  * 
  * Unusable options:
  * 	- inputDefaults
  * 
  * @param $model The model corresponding to the form
  * @param $options Options to customize the form
  * 
  * @return The HTML tags corresponding to the openning of the form
  * 
  **/
 public function create($model = null, array $options = array())
 {
     if (isset($options['cols'])) {
         $this->colSize = $options['cols'];
         unset($options['cols']);
     } else {
         $this->colSize = $this->_defaultColumnSize;
     }
     $this->horizontal = $this->_extractOption('horizontal', $options, false);
     unset($options['horizontal']);
     $this->search = $this->_extractOption('search', $options, false);
     unset($options['search']);
     $this->inline = $this->_extractOption('inline', $options, false);
     unset($options['inline']);
     if ($this->horizontal) {
         $options = $this->addClass($options, 'form-horizontal');
     } else {
         if ($this->inline) {
             $options = $this->addClass($options, 'form-inline');
         }
     }
     if ($this->search) {
         $options = $this->addClass($options, 'form-search');
     }
     $options['role'] = 'form';
     $this->templates(['formGroup' => '{{label}}' . ($this->horizontal ? '<div class="' . $this->_getColClass('input') . '">' : '') . '{{prepend}}{{input}}{{append}}' . ($this->horizontal ? '</div>' : ''), 'checkboxContainer' => ($this->horizontal ? '<div class="form-group"><div class="' . $this->_getColClass('label', true) . ' ' . $this->_getColClass('input') . '">' : '') . '<div class="checkbox">{{content}}</div>' . ($this->horizontal ? '</div></div>' : ''), 'radioContainer' => ($this->horizontal ? '<div class="form-group"><div class="' . $this->_getColClass('label', true) . ' ' . $this->_getColClass('input') . '">' : '') . '{{content}}' . ($this->horizontal ? '</div></div>' : ''), 'label' => '<label class="' . ($this->horizontal ? $this->_getColClass('label') : '') . ' ' . ($this->inline ? 'sr-only' : 'control-label') . ' {{attrs.class}}" {{attrs}}>{{text}}</label>', 'error' => '<span class="help-block ' . ($this->horizontal ? $this->_getColClass('error') : '') . '">{{content}}</span>', 'submitContainer' => '<div class="form-group">' . ($this->horizontal ? '<div class="' . $this->_getColClass('label', true) . ' ' . $this->_getColClass('input') . '">' : '') . '{{content}}' . ($this->horizontal ? '</div>' : '') . '</div>']);
     return parent::create($model, $options);
 }
Пример #10
0
 /**
  * Returns an inline form element.
  *
  * You can also create an inline form using the `create()` method with
  *  the `inline` option.
  *
  * Note that by default `createInline` doesn't display help blocks and
  *  errors.
  * @param mixed $model The model name for which the form is being defined.
  *  If `false` no model is used
  * @param array $options HTML attributes and options
  * @return string An formatted opening `<form>` tag
  * @uses $inline
  */
 public function createInline($model = null, array $options = [])
 {
     $this->inline = true;
     unset($options['inline']);
     $options = $this->optionsValues(['class' => 'form-inline'], $options);
     return parent::create($model, $options);
 }
Пример #11
0
 /**
  * 
  * Create a Twitter Bootstrap like form. 
  * 
  * New options available:
  * 	- horizontal: boolean, specify if the form is horizontal
  * 	- inline: boolean, specify if the form is inline
  * 	- search: boolean, specify if the form is a search form
  * 
  * Unusable options:
  * 	- inputDefaults
  * 
  * @param $model The model corresponding to the form
  * @param $options Options to customize the form
  * 
  * @return The HTML tags corresponding to the openning of the form
  * 
  **/
 public function create($model = null, array $options = array())
 {
     if (isset($options['cols'])) {
         $this->colSize = $options['cols'];
         unset($options['cols']);
     } else {
         $this->colSize = $this->defaultColumnSize;
     }
     $this->horizontal = $this->_extractOption('horizontal', $options, false);
     unset($options['horizontal']);
     $this->search = $this->_extractOption('search', $options, false);
     unset($options['search']);
     $this->inline = $this->_extractOption('inline', $options, false);
     unset($options['inline']);
     if ($this->horizontal) {
         $options = $this->addClass($options, 'form-horizontal');
     } else {
         if ($this->inline) {
             $options = $this->addClass($options, 'form-inline');
         }
     }
     if ($this->search) {
         $options = $this->addClass($options, 'form-search');
     }
     $options['role'] = 'form';
     $this->templates(['inputContainer' => '<div class="form-group {{type}}{{required}}">{{content}}</div>', 'inputContainerError' => '<div class="form-group has-error {{type}}{{required}}">{{content}}{{error}}</div>', 'formGroup' => '{{label}}' . ($this->horizontal ? '<div class="' . $this->_getColClass('input') . '">' : '') . '{{input}}' . ($this->horizontal ? '</div>' : ''), 'input' => '<input class="form-control input-sm" type="{{type}}" name="{{name}}"{{attrs}}/>', 'select' => '<select class="form-control select select-primary select-block" name="{{name}}"{{attrs}}>{{content}}</select>', 'selectMultiple' => '<select class="form-control select select-primary select-block" name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>', 'textarea' => '<textarea class="form-control" name="{{name}}"{{attrs}}>{{value}}</textarea>', 'checkboxContainer' => '<div class="form-group">' . ($this->horizontal ? '<div class="' . $this->_getColClass('label', true) . ' ' . $this->_getColClass('input') . '">' : '') . '<div class="checkbox">{{content}}</div>' . ($this->horizontal ? '</div>' : '') . '</div>', 'radioContainer' => '<div class="form-group">' . ($this->horizontal ? '<div class="' . $this->_getColClass('label', true) . ' ' . $this->_getColClass('input') . '">' : '') . '{{content}}' . ($this->horizontal ? '</div>' : '') . '</div>', 'radioWrapper' => '<div class="radio">{{label}}</div>', 'label' => '<label class="' . ($this->horizontal ? $this->_getColClass('label') : '') . ' ' . ($this->inline ? 'sr-only' : 'control-label') . '" {{attrs}}>{{text}}</label>', 'error' => '<span class="help-block ' . ($this->horizontal ? $this->_getColClass('error') : '') . '">{{content}}</span>', 'submitContainer' => '<div class="form-group">' . ($this->horizontal ? '<div class="' . $this->_getColClass('label', true) . ' ' . $this->_getColClass('input') . '">' : '') . '{{content}}' . ($this->horizontal ? '</div>' : '') . '</div>']);
     return parent::create($model, $options);
 }
 /**
  *
  * Create a Twitter Bootstrap like form.
  *
  * New options available:
  *     - horizontal: boolean, specify if the form is horizontal
  *     - inline: boolean, specify if the form is inline
  *     - search: boolean, specify if the form is a search form
  *
  * Unusable options:
  *     - inputDefaults
  *
  * @param $model The model corresponding to the form
  * @param $options Options to customize the form
  *
  * @return The HTML tags corresponding to the openning of the form
  *
  **/
 public function create($model = null, array $options = array())
 {
     $options += ['columns' => $this->config('columns'), 'horizontal' => false, 'inline' => false];
     $this->colSize = $options['columns'];
     $this->horizontal = $options['horizontal'];
     $this->inline = $options['inline'];
     unset($options['columns'], $options['horizontal'], $options['inline']);
     if ($this->horizontal) {
         $options = $this->addClass($options, 'form-horizontal');
     } else {
         if ($this->inline) {
             $options = $this->addClass($options, 'form-inline');
         }
     }
     $options['role'] = 'form';
     return parent::create($model, $options);
 }
Пример #13
0
 /**
  * Create html form.
  *
  * @param null $model
  * @param array $options
  * @return string
  */
 public function create($model = null, array $options = [])
 {
     $options = $this->addClass($options, 'un-form');
     if (isset($options['jsForm']) && $options['jsForm']) {
         $options = $this->addClass($options, 'jsForm');
         unset($options['jsForm']);
     }
     return parent::create($model, $options);
 }