BootstrapUI\View\Helper\FormHelper::create PHP Method

create() public method

Returns an HTML FORM element.
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.
return string An formatted opening FORM tag.
    public function create($model = null, array $options = [])
    {
        // @codeCoverageIgnoreStart
        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.');
        }
        // @codeCoverageIgnoreEnd
        $options += ['class' => null, 'role' => 'form', 'align' => null, 'templates' => []];
        return parent::create($model, $this->_formAlignment($options));
    }

Usage Example

 public function testHelpTextHorizontal()
 {
     $this->Form->create($this->article, ['align' => 'horizontal']);
     $result = $this->Form->input('title', ['help' => 'help text']);
     $expected = ['div' => ['class' => 'form-group text required'], 'label' => ['class' => 'control-label col-md-2', 'for' => 'title'], 'Title', '/label', ['div' => ['class' => 'col-md-6']], 'input' => ['type' => 'text', 'name' => 'title', 'id' => 'title', 'class' => 'form-control', 'required' => 'required'], ['div' => ['class' => 'help-block']], 'help text', '/div', '/div', '/div'];
     $this->assertHtml($expected, $result);
     $result = $this->Form->input('published', ['help' => 'help text']);
     $expected = ['div' => ['class' => 'form-group checkbox'], ['div' => ['class' => 'col-md-offset-2 col-md-6']], ['div' => ['class' => 'checkbox']], 'input' => ['type' => 'hidden', 'name' => 'published', 'value' => 0], 'label' => ['for' => 'published'], ['input' => ['type' => 'checkbox', 'name' => 'published', 'id' => 'published', 'value' => 1]], 'Published', '/label', '/div', ['div' => ['class' => 'help-block']], 'help text', '/div', '/div', '/div'];
     $this->assertHtml($expected, $result);
     $this->article['errors'] = ['title' => ['error message']];
     $this->Form->create($this->article, ['align' => 'horizontal']);
     $result = $this->Form->input('title', ['help' => 'help text']);
     $expected = ['div' => ['class' => 'form-group text required has-error'], 'label' => ['class' => 'control-label col-md-2', 'for' => 'title'], 'Title', '/label', ['div' => ['class' => 'col-md-6']], 'input' => ['type' => 'text', 'name' => 'title', 'id' => 'title', 'class' => 'form-control', 'required' => 'required'], ['div' => ['class' => 'help-block']], 'error message', '/div', ['div' => ['class' => 'help-block']], 'help text', '/div', '/div', '/div'];
     $this->assertHtml($expected, $result);
 }
All Usage Examples Of BootstrapUI\View\Helper\FormHelper::create