/** * Registers common function in Twig * * @param \Phalcon\Mvc\ViewInterface $view * @param \Phalcon\DiInterface $di * @param array $userFunctions */ protected function registryFunctions($view, DiInterface $di, $userFunctions = array()) { $options = array('is_safe' => array('html')); $functions = array(new \Twig_SimpleFunction('content', function () use($view) { return $view->getContent(); }, $options), new \Twig_SimpleFunction('partial', function ($partialPath) use($view) { return $view->partial($partialPath); }, $options), new \Twig_SimpleFunction('linkTo', function ($parameters, $text = null) { return \Phalcon\Tag::linkTo($parameters, $text); }, $options), new \Twig_SimpleFunction('textField', function ($parameters) { return \Phalcon\Tag::textField($parameters); }, $options), new \Twig_SimpleFunction('passwordField', function ($parameters) { return \Phalcon\Tag::passwordField($parameters); }, $options), new \Twig_SimpleFunction('hiddenField', function ($parameters) { return \Phalcon\Tag::hiddenField($parameters); }, $options), new \Twig_SimpleFunction('fileField', function ($parameters) { return \Phalcon\Tag::fileField($parameters); }, $options), new \Twig_SimpleFunction('checkField', function ($parameters) { return \Phalcon\Tag::checkField($parameters); }, $options), new \Twig_SimpleFunction('radioField', function ($parameters) { return \Phalcon\Tag::radioField($parameters); }, $options), new \Twig_SimpleFunction('submitButton', function ($parameters) { return \Phalcon\Tag::submitButton($parameters); }, $options), new \Twig_SimpleFunction('selectStatic', function ($parameters, $data = array()) { return \Phalcon\Tag::selectStatic($parameters, $data); }, $options), new \Twig_SimpleFunction('select', function ($parameters, $data = array()) { return \Phalcon\Tag::select($parameters, $data); }, $options), new \Twig_SimpleFunction('textArea', function ($parameters) { return \Phalcon\Tag::textArea($parameters); }, $options), new \Twig_SimpleFunction('form', function ($parameters = array()) { return \Phalcon\Tag::form($parameters); }, $options), new \Twig_SimpleFunction('endForm', function () { return \Phalcon\Tag::endForm(); }, $options), new \Twig_SimpleFunction('getTitle', function () { return \Phalcon\Tag::getTitle(); }, $options), new \Twig_SimpleFunction('stylesheetLink', function ($parameters = null, $local = true) { return \Phalcon\Tag::stylesheetLink($parameters, $local); }, $options), new \Twig_SimpleFunction('javascriptInclude', function ($parameters = null, $local = true) { return \Phalcon\Tag::javascriptInclude($parameters, $local); }, $options), new \Twig_SimpleFunction('image', function ($parameters) { return \Phalcon\Tag::image($parameters); }, $options), new \Twig_SimpleFunction('friendlyTitle', function ($text, $separator = null, $lowercase = true) { return \Phalcon\Tag::friendlyTitle($text, $separator, $lowercase); }, $options), new \Twig_SimpleFunction('getDocType', function () { return \Phalcon\Tag::getDocType(); }, $options), new \Twig_SimpleFunction('getSecurityToken', function () use($di) { return $di->get("security")->getToken(); }, $options), new \Twig_SimpleFunction('getSecurityTokenKey', function () use($di) { return $di->get("security")->getTokenKey(); }, $options), new \Twig_SimpleFunction('url', function ($route) use($di) { return $di->get("url")->get($route); }, $options)); if (!empty($userFunctions)) { $functions = array_merge($functions, $userFunctions); } foreach ($functions as $function) { $this->twig->addFunction($function); } }
/** * Start BForm * @param string $link The url that form data will be summited to * @param array $params * @return string The result returned by function Tag::form() */ public function start($link, $params = []) { array_unshift($params, $link); if (!isset($params['method'])) { $params['method'] = 'post'; } $params['role'] = 'form'; return Tag::form($params); }
/** * Registers common function in Twig * * @param \Phalcon\Mvc\ViewInterface $view */ private function registryFunctions($view) { $options = array('is_safe' => array('html')); $functions = array(new \Twig_SimpleFunction('content', function () use($view) { return $view->getContent(); }, $options), new \Twig_SimpleFunction('partial', function ($partialPath) use($view) { return $view->partial($partialPath); }, $options), new \Twig_SimpleFunction('linkTo', function ($parameters, $text = null) { return \Phalcon\Tag::linkTo($parameters, $text); }, $options), new \Twig_SimpleFunction('textField', function ($parameters) { return \Phalcon\Tag::textField($parameters); }, $options), new \Twig_SimpleFunction('passwordField', function ($parameters) { return \Phalcon\Tag::passwordField($parameters); }, $options), new \Twig_SimpleFunction('hiddenField', function ($parameters) { return \Phalcon\Tag::hiddenField($parameters); }, $options), new \Twig_SimpleFunction('fileField', function ($parameters) { return \Phalcon\Tag::fileField($parameters); }, $options), new \Twig_SimpleFunction('checkField', function ($parameters) { return \Phalcon\Tag::checkField($parameters); }, $options), new \Twig_SimpleFunction('radioField', function ($parameters) { return \Phalcon\Tag::radioField($parameters); }, $options), new \Twig_SimpleFunction('submitButton', function ($parameters) { return \Phalcon\Tag::submitButton($parameters); }, $options), new \Twig_SimpleFunction('selectStatic', function ($parameters, $data = []) { return \Phalcon\Tag::selectStatic($parameters, $data); }, $options), new \Twig_SimpleFunction('select', function ($parameters, $data = []) { return \Phalcon\Tag::select($parameters, $data); }, $options), new \Twig_SimpleFunction('textArea', function ($parameters) { return \Phalcon\Tag::textArea($parameters); }, $options), new \Twig_SimpleFunction('form', function ($parameters = []) { return \Phalcon\Tag::form($parameters); }, $options), new \Twig_SimpleFunction('endForm', function () { return \Phalcon\Tag::endForm(); }, $options), new \Twig_SimpleFunction('getTitle', function () { return \Phalcon\Tag::getTitle(); }, $options), new \Twig_SimpleFunction('getTitle', function () { return \Phalcon\Tag::getTitle(); }, $options), new \Twig_SimpleFunction('stylesheetLink', function ($parameters = null, $local = true) { return \Phalcon\Tag::stylesheetLink($parameters, $local); }, $options), new \Twig_SimpleFunction('javascriptInclude', function ($parameters = null, $local = true) { return \Phalcon\Tag::javascriptInclude($parameters, $local); }, $options), new \Twig_SimpleFunction('image', function ($parameters) { return \Phalcon\Tag::image($parameters); }, $options), new \Twig_SimpleFunction('friendlyTitle', function ($text, $separator = null, $lowercase = true) { return \Phalcon\Tag::friendlyTitle($text, $separator, $lowercase); }, $options), new \Twig_SimpleFunction('getDocType', function () { return \Phalcon\Tag::getDocType(); }, $options)); foreach ($functions as $function) { $this->_twig->addFunction($function); } }
<?php use Phalcon\Tag; ?> <!-- Sending the form by method POST --> <?php echo Tag::form("products/search"); ?> <label for="q">Search:</label> <?php echo Tag::textField("q"); echo Tag::submitButton("Search"); ?> </form> <!-- Specyfing another method or attributes for the FORM tag --> <?php echo Tag::form(array("products/search", "method" => "get")); ?> <label for="q">Search:</label> <?php echo Tag::textField("q"); echo Tag::submitButton("Search"); ?> </form>
public function start(array $attributes = []) { $this->setAttributes($attributes); $tags = array(); $tags[] = Tag::form($this->getAttributes()); $elements = $this->getElements(); if ($elements) { foreach ($this->getElements() as $element) { if ($this->getElementType($element) == 'hidden') { $tags[] = $element->render(); } } } return implode("", $tags); }
public static function form($parameters) { return parent::form($parameters); }
/** * Form open tag. * * @return string */ public function openTag() { return Tag::form(array_merge($this->getAttributes(), [$this->getAction(), 'method' => $this->getMethod(), 'enctype' => $this->getEncodingType()])); }
/** * Tests form with an array as parameters * * @issue 57 * @author Nikos Dimopoulos <*****@*****.**> * @since 2012-11-29 */ public function testFormWithArrayParametersPostT57() { $params = array('about/list', 'method' => 'post'); $expected = '<form action="/about/list" method="post">'; $actual = PhTag::form($params); $this->assertEquals($expected, $actual, sprintf($this->message, 'form with array parameters post')); }
<?php use Phalcon\Tag; ?> <h2>Sign using this form</h2> <?php echo Tag::form("signup/register"); ?> <p> <label for="name">Name</label> <?php echo Tag::textField("name"); ?> </p> <p> <label for="name">E-Mail</label> <?php echo Tag::textField("email"); ?> </p> <p> <?php echo Tag::submitButton("Register"); ?> </p>