public function __construct($action = null, $method = 'post', array $options = array())
 {
     parent::__construct($action, $method, $options);
     $name = new Text('name', 'name');
     $name->sanitizer(new StringSanitizer())->setAttr('class', 'form-control')->setAttr('placeholder', 'Your Name')->filter(new NotEmptyFilter(), 'Please enter your name.')->label("Name");
     $email = new Text('email', 'email');
     $email->sanitizer(new StringSanitizer());
     $email->filter(new NotEmptyFilter(), "You must enter an email address.");
     $email->filter(new EmailFilter(), "You must enter a valid email address.");
     $email->setAttr('placeholder', '*****@*****.**')->setAttr('class', 'form-control');
     $email->label("Email");
     $url = new Text('url', 'url');
     $url->sanitizer(new StringSanitizer());
     $url->filter(new UrlFilter(), "You must enter a valid URL.");
     $url->setAttr('placeholder', 'http://www.example.com')->setAttr('class', 'form-control');
     $url->label("Website");
     $parent = new Hidden('parent', 'parent');
     $parent->sanitizer(new IntegerSanitizer());
     $parent->filter(new RegexFilter('/[0-9]{0,11}/'), "Invalid parent comment");
     $parent->setDefault(null);
     $comment = new TextArea('comment', 'comment');
     $comment->sanitizer(new StringSanitizer());
     $comment->filter(new NotEmptyFilter(), "You must enter a comment.");
     $comment->setAttr('placeholder', 'Enter a comment');
     $comment->label("Comment")->setAttr('class', 'form-control');
     $submit = new Submit();
     $submit->setAttr('class', 'btn btn-default')->setDefault('Post comment');
     $this->addAll(array($name, $email, $url, $comment, $parent, $submit));
 }
Beispiel #2
0
 /**
  *
  * @param Form $form
  *
  * @return string
  */
 public function renderElement(Element $element, Form $form)
 {
     $contents = "";
     $form->notify(new FormEvent(Events::BEFORE_ELEMENT_RENDER, $form, array('renderer' => $this, 'contents' => &$contents), $element));
     ob_start();
     $resource = $this->getElementResource($element);
     include $resource;
     $contents .= ob_get_clean();
     $form->notify(new FormEvent(Events::AFTER_ELEMENT_RENDER, $form, array('renderer' => $this, 'contents' => &$contents), $element));
     return $contents;
 }