Exemple #1
0
 /**
  * Constructor
  *
  * Creates a new comment form instance.
  *
  * @param array  $fields  Collection of form fields.
  */
 public function __construct($fields = array())
 {
     // Ensure the session is started
     Session::start();
     // Setup form container
     $this->addClass('form comment-form');
     // Set default action endpoint
     $hash = page()->hash();
     $this->method('post');
     $this->action(url("/api/pages/{$hash}/comments/create"));
     // Provide default fields if none are given
     $this->fields = array();
     if (empty($fields)) {
         $this->defaults();
     } else {
         $this->fields($fields);
     }
     // Populate message collection from session
     $this->messages = new Messages();
     if ($errors = Session::get('errors')) {
         $this->messages->add($errors);
     }
     // Collect field data
     $this->data = $this->input();
     // Perform form validation on submit
     $this->on('submit', function ($form) {
         $form->validate();
     });
 }