title: Validation in Redbean PHP
body: <p>I like the idea of using FUSE models for validation in RedbeanPHP.</p>
  
  <p>My applications sometimes require accepting data through multiple sources (form, file, etc.), so putting the validation on the actual class update makes sense.</p>
  
  <p>Looking at the examples on the Redbean site, the validation seems to be based on throwing an exception.</p>
  
  <p>Of course, you can only throw one exception, so I am assuming I'd need to create an additional property of type "array" in my FUSE class to hold validations messages associated with individual fields.</p>
  
  <p>Does anyone have any better ideas? Here's what I've been trying thus far...</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
      &lt;p&gt;your name: &lt;input name="name" type="text"&gt;&lt;/p&gt;
  
      &lt;p&gt;your email: &lt;input name="email" type="text"&gt;&lt;/p&gt;
  
      &lt;p&gt;your message:&lt;/p&gt;
      &lt;textarea name="message" id="" cols="30" rows="10"&gt;&lt;/textarea&gt;
      &lt;input name="send" value="send message" type="submit"&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  /**
   * @property $name string
   * @property $email string
   * @property $message string
   */
  class Model_Comment extends RedBean_SimpleModel{
      public $invalid = array();
      public function update(){
          if(empty($this-&gt;name)) $this-&gt;invalid['name'] = "field is empty";
          if(empty($this-&gt;email)) $this-&gt;invalid['email'] = "field is empty";
          if(empty($this-&gt;message)) $this-&gt;invalid['message'] = "field is empty";
          if(count($this-&gt;invalid) &gt; 0) throw new Exception('Validation Failed!');
      }
      public function getInvalid(){
          return $this-&gt;invalid;
      }
  }
  
  if(isset($_POST['send'])){
  
      $comment = R::dispense('comment');
      /* @var $comment Model_Comment */
      $comment-&gt;import($_POST,'name,email,message');
  
      try{
          R::store($comment);
      }
      catch(Exception $e){
          echo $e-&gt;getMessage();
          $invalid = $comment-&gt;getInvalid();
          print_r($invalid);
          exit;
      }
      echo '&lt;p&gt;thank you for leaving a message.&lt;/p&gt;';
  }
  echo "&lt;h2&gt;What people said!&lt;/h2&gt;";
  
  $comments = R::find('comment');
  /* @var $comments Model_Comment[] */
  
  foreach($comments as $comment){
      echo "&lt;p&gt;{$comment-&gt;name}: {$comment-&gt;message}&lt;/p&gt;";
  }
  
  ?&gt;
  </code></pre>