phalcon: 表单

Posted 穆晟铭

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了phalcon: 表单相关的知识,希望对你有一定的参考价值。

以实例为说明:

controller

<?php
use \Phalcon\Forms\Form;
use \Phalcon\Forms\Element\Text;
use \Phalcon\Forms\Element\Select;
use \Phalcon\Mvc\Controller,
	Phalcon\Validation\Validator\PresenceOf,
    Phalcon\Validation\Validator\StringLength;
class FormController extends Controller
{
	public function indexAction()
	{
		$form = new Form();

              //例子一:
		$form->add(new Text("name", array(
			"maxlength" => 20,
			"placeholder"=>‘you name‘
		)));

               //例子二:
		$form->add(new Text("telphone"));

                //例子三:
               //例子三我有不明白的地方,该怎么调用他的验证。
		$passwd = new Text("passwd");
		$passwd->addValidator(new PresenceOf(array(
			‘message‘ => ‘The passwd is required‘
		)));
		$passwd->addValidator(new StringLength(array(
			‘min‘ => 10,
			‘messageMinimum‘ => ‘The passwd is too short‘
		)));
		$form->add($passwd);

		
		
		$this->view->pick("form/form");
		$this->view->form=$form;
	}

	
}
?>    

  

phtml

<html>
<title>aaa</title>
<body>

<?php echo $this->tag->form("form/test");?>

<?php echo $form->render("name") ?>
<br>
<?php echo $form->render("telphone", array("maxlength"=>20, "placeholder"=>"you telphone"));?>
<br>
<?php echo $form->render("passwd") ?>




<br>
<?php echo $this->tag->submitButton("login");?>
</form>

</body>
</html>

  

 

以上是关于phalcon: 表单的主要内容,如果未能解决你的问题,请参考以下文章

在输入字段下显示表单错误消息 Phalcon php

如何使用 phalcon 上传多个图像并将其名称存储在数据库中?

phalcon: Windows 下 Phalcon dev-tools 配置 和 Phpstorm中配置Phalcon 代码提示

Phalcon路线冲突

phpstudy下安装phalcon

Phalcon学习笔记