TbHtml::searchForm PHP Method

searchForm() public static method

Generates a search form.
public static searchForm ( mixed $action, string $method = 'post', array $htmlOptions = [] ) : string
$action mixed the form action URL.
$method string form method (e.g. post, get).
$htmlOptions array additional HTML options.
return string the generated form.
    public static function searchForm($action, $method = 'post', $htmlOptions = array())
    {
        self::addCssClass('form-search', $htmlOptions);
        $inputOptions = TbArray::popValue('inputOptions', $htmlOptions, array());
        $inputOptions = TbArray::merge(array('type' => 'text', 'placeholder' => 'Search'), $inputOptions);
        $name = TbArray::popValue('name', $inputOptions, 'search');
        $value = TbArray::popValue('value', $inputOptions, '');
        $output = self::beginFormTb(self::FORM_LAYOUT_SEARCH, $action, $method, $htmlOptions);
        $output .= self::searchQueryField($name, $value, $inputOptions);
        $output .= parent::endForm();
        return $output;
    }

Usage Example

Exemplo n.º 1
0
 public function testSearchForm()
 {
     $I = $this->codeGuy;
     $html = TbHtml::searchForm('#', 'post', array('class' => 'form'));
     $form = $I->createNode($html, 'form.form-search');
     $I->seeNodeCssClass($form, 'form');
     $I->seeNodeAttributes($form, array('action' => '#', 'method' => 'post'));
     $input = $form->filter('input[type=text]');
     $I->seeNodeCssClass($input, 'search-query');
 }
TbHtml