> [mailto:[EMAIL PROTECTED] On Behalf Of RosSoft
> invalidate() sets a row in an array with a value of 1. Change
> invalidate() to set the string as value (then the errors will be
> available in your controller and helpers)

Nice. So I could override invalidate in app_model:

/*  +++  */
function invalidate( $field, $errMsg = null ) 
{
   if (!is_array($this->validationErrors)) 
   {
       $this->validationErrors = array();
   }
   if ( $errMsg == null )
   {
      $bits = explode('_', $field) ;
      $nameBits = array() ;
      foreach( $bits as $bit )
      {
         $nameBits[] = ucfirst( $bit ) ;
      }
      $name = join( ' ', $nameBits ) ;
      $msg = "Invalid $name value" ;
   }
   else
   {
      $msg = $errMsg ;
   }

   $this->validationErrors[$field] = $msg ;
}
/*  +++  */

Then in my beforeValidate():

/*  +++  */
 function beforeValidate()
 {
   $this->invalidate( 'username', 'User name already taken' ) ;
   return false ;
 }
/*  +++  */

Then, using ErrorHelper::tagErrorMsg as a drop-in replacement for
HtmlHelper::tagErrorMsg :

/*  +++  */
class ErrorHelper extends Helper 
{
   var $helpers = array( 'Html' ) ;
   
   function tagErrorMsg( $field ) 
   {
      $this->Html->setFormTag($field) ;
      $msg = $this->Html->tagIsInvalid($this->Html->model,
$this->Html->field) ;
      if ( !$msg )
      {
         return null ;
      }
      return sprintf('<div class="error_message">%s</div>', $msg ) ;
   }
}
/*  +++  */

// ========

How does that look?

--
Regards,
Ryan Ginstrom


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to