Since this might save someone some time i implemented your (b) option in a
semi-generalized way here:

http://bin.cakephp.org/view/152660210

the past includes a demo validate array and an addon to validates that works
with optional fields for which i misuse the allowEmpty variable. feel free
to comment if you see any issues but this seems to work fine with my code at
least.


GreyCells-2 wrote:
> 
> 
> allowEmpty actually translates to 'not set' i.e. if the field is not
> set in the model then don't fail validation. I think what you're
> looking for is similar to me - i.e.  'allowBlank' - ala
> https://trac.cakephp.org/ticket/2092  Use at your own risk as this
> patch may not be accepted and 1.2 is still under serious development.
> 
> A better alternative at this stage (rather than patching the core) is
> to either a) unset blank fields in beforeValidate() or b) manually
> validate optional fields in validates() then call parent::validates()
> and return the result. I've taken option b - with a //TODO note to
> refactor once allow blank functionality comes into the core - which
> I'm sure it will, just maybe not as the above patch :)
> 
> On Feb 18, 12:39 pm, Tijs Teulings <[EMAIL PROTECTED]> wrote:
>> I was hoping something like allowEmpty would be implemented soon so i
>> could
>> really start using 1.2 but, using the latest dev release, i still get
>> 'this
>> field cannot be left blank' errors even when i set allowEmpty to true. I
>> tried several variants on the example you give but no dice.
>>
>> Validating non-required fields and integration of custom functions in the
>> built in validation would allow me to switch to 1.2 completely. I'll take
>> the random API changes for granted when i could do that now.
>>
>> Tijs
>>
>>
>>
>> GreyCells-2 wrote:
>>
>> > The way it appears to work now (I'm sure nate will correct me if I'm
>> > wrong) is to put your error messages in the model. Here is an example
>> > of an email validation:
>>
>> > var $validate = array(
>> >          'email_address' => array( array('allowEmpty' => false
>> >            ,'message' => 'Invalid email address format or unknown
>> > domain')
>> >            , 'rule' => array('email', true)
>> >    ),
>> > );
>>
>> > Note the 'message' element in the array. It will also display the
>> > second argument of $Model->invalidate('field_name', 'My custom
>> > message'); if you happen to be doing stuff in $Model->validates()
>>
>> > Use the $form->input() 'wrapper' and the error messages will be
>> > rendered automatically without having to call tagErrorMessage i.e.
>> > this is all you need in your view:
>>
>> > <?php echo $form->input('email_address', array('class' =>
>> > 'required'));?>
>>
>> > On Feb 18, 4:12 am, "gobblez" <[EMAIL PROTECTED]> wrote:
>> >> Hello, in the latest 1.2 SVN,  I can't get validation to work.  Well,
>> >> it is working, the empty fields are being flagged as they should be
>> >> for not meeting cake's regex constants, but my tagErrorMsg definitions
>> >> aren't spitting out their messages.
>>
>> >> I did a search, and found it on line 1685 of model.php  What I did, is
>> >> changed 'This field cannot be left blank' to '1'.  It works now, but
>> >> I'm thinking maybe tagErrorMsg is used differently now.
>>
>> >> Here is an example of how I've been using it, and it works when a
>> >> flagged field is set to '1' instead of that 'this field cannot..."
>> >> sentence.
>>
>> >> echo $html->tagErrorMsg('User/username', '<span class="error">Please
>> >> enter a username.</span><br />');
>>
>> --
>> View this message in
>> context:http://www.nabble.com/1.2-validation---This-field-cannot-be-left-blan...
>> Sent from the CakePHP mailing list archive at Nabble.com.
> 
> 
> > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/1.2-validation---This-field-cannot-be-left-blank-tf3247151.html#a9042798
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to