以实例为说明:
controller
<?php use PhalconFormsForm; use PhalconFormsElementText; use PhalconFormsElementSelect; use PhalconMvcController, PhalconValidationValidatorPresenceOf, PhalconValidationValidatorStringLength; 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>