Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-26-2008, 06:44 PM
Junior Member
 
Join Date: Oct 2008
Posts: 2
Question Zend Form custom validation errors

Hi everyone,

I've been experimenting with Zend Forms lately and I encountered the same problem for the last couple of days and I can't really solve this on my own. The main idea is that I want to display my error messages in my own language.
These are some lines of my Form:

<?php
$starttime = new Zend_Form_Element_Text('starttime');
$starttime->setLabel('Start tijd (in de vorm "YYYY-MM-DD hh:mm")')
->setRequired(true)
->addValidator('NotEmpty',
true,
array('messages' =>
array('isEmpty' => 'Empty!')))
->addValidator(new Zend_Validate_Date('YYYY-MM-DD hh:mm'),
true,
array('messages' =>
array(Zend_Validate_Date::FALSEFORMAT => 'Waarde is niet goeedd')));
?>



When I submit my Form, ZF validates my input, but my "starttime"-field doesn't get validated like I want to:

<?
array(6) {
["starttime"]=>
array(1) {
["dateFalseFormat"]=>
string(34) "'a' does not fit given date format"
}
... and some more
}
?>

As you can see, my starttime errormessage is just the default errormessage "'a' does not fit given date format" (because I entered a wrong date format). I think that's strange because I defined that as "Waarde is niet goeedd". When I don't fill in anything, the validation does go as I want it to: it gives my custom errormessage "Empty!"

Do you have any solutions for my problem? Am I doing something terrible wrong?

Thanks a lot in advance,
Arthur
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-27-2008, 08:31 AM
Member
 
Join Date: Sep 2008
Location: Croatia
Posts: 57
Default

you can use zend_translate ( Zend Framework: Documentation )
or you can set custom error messages ( Zend Framework: Documentation ).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-27-2008, 04:03 PM
Junior Member
 
Join Date: Oct 2008
Posts: 2
Default

Thanks for the response.
I have already seen this option, but I thought that is was possible to define these error messages in my Zend Form object as well... It does work in the isEmpty validation, but it does not work in the date validation! Seems like I'm doing something wrong or will I just have to define these messages in my Controller anyway?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:29 AM.