And as i thought I am already in trouble:
See comments in the code below.

public function isValid($value, $context = null){
        $date = new Zend_Date($value,'dd-MM-YYYY');
        $this->_setValue($value);

        $error = false;
       var_dump($this->_fieldsToCompare);
      //this dump shows me the acutal text box in the form with the date in
it and the label and so on.
        foreach($this->_fieldsToCompare as $fieldName){
            echo $context[$fieldName];
            //this echo is empty.
            if(!isset($context[$fieldName]) || $value !==
$context[$fieldName]){
                $error = true;
                $this->_error(self::MSG_DATEBEFORE);
                break;
            }
        }
        return !$error;
    }

What i need is the value of the startDate which i have given in my
addValidator function
:$evtEndDate->addValidator('CompareDates',false,array<http://www.php.net/array>
($evtStartDate)); and then convert it to a date object in order to be able
to compate dates with the isEarlier function.
How can i do this?

On Wed, Dec 30, 2009 at 10:04 PM, Jigal sanders <[email protected]>wrote:

> figured it out , i think.
> I changed my construct function to:
>
> public function __construct($fieldsToCompare =array()){
>         if(is_array($fieldsToCompare)){
>             foreach($fieldsToCompare as $field){
>                 echo $field;
>                 exit;
>                 $this->_fieldsToCompare[] = $field;
>             }
>         }else{
>                 $this->_fieldsToCompare[] = (string)$fieldsToCompare;
>         }
>
>
>     }
>
> No i have to see in my further code if i can use it since i need to make it
> to a zend_date object later on in my isValid function.
>
>
> On Wed, Dec 30, 2009 at 10:02 PM, Hector Virgen <[email protected]>wrote:
>
>> What is the value of $evtStartDate before calling addValidator()?
>>
>> --
>> Hector
>>
>>
>>
>> On Wed, Dec 30, 2009 at 12:48 PM, Jigal sanders <[email protected]>wrote:
>>
>>> sorry to disturb but i really don't get it working.
>>> It starts already that in the constructor the $_fieldsToCompare array
>>> stays empty. While this is the way i instantiate the validator:
>>>
>>> $evtEndDate->addValidator('CompareDates',false,array<http://www.php.net/array>
>>> ($evtStartDate));
>>>
>>> this is the full code
>>>
>>> http://pastebin.com/f5f36971f
>>>
>>>
>>> On Wed, Dec 30, 2009 at 7:46 PM, Hector Virgen <[email protected]>wrote:
>>>
>>>> You might want to look at the Zend_Date documentation for comparing
>>>> dates.
>>>>
>>>>
>>>> http://framework.zend.com/manual/en/zend.date.overview.html#zend.date.others.comparison
>>>>
>>>>
>>>> <http://framework.zend.com/manual/en/zend.date.overview.html#zend.date.others.comparison>You
>>>> can hint to your validator (perhaps with another constructor argument) as 
>>>> to
>>>> how to compare the dates... should A be before B, or after B, or equal to 
>>>> B?
>>>>
>>>> --
>>>> Hector
>>>>
>>>>
>>>>
>>>> On Wed, Dec 30, 2009 at 10:42 AM, Jigal sanders 
>>>> <[email protected]>wrote:
>>>>
>>>>> Hello Hector,
>>>>>
>>>>> I already removed the validator by one of the date fields.
>>>>> Now the problem is on how to compare the dates. I created date objects
>>>>> from all the date fields within the validator. But I don't know how to do
>>>>> the last part (i.e comparing the dates.) I converted the field values to
>>>>> zend_date objects. But when I print the date object to the screen i get:
>>>>>
>>>>> array(1) { [0]=> object(Zend_Date)#109 (8) { ["_locale:private"]=>
>>>>> string(5) "en_US" ["_fractional:private"]=> int(0) 
>>>>> ["_precision:private"]=>
>>>>> int(3) ["_unixTimestamp:private"]=> string(10) "1262127600"
>>>>> ["_timezone:private"]=> string(16) "Europe/Amsterdam" 
>>>>> ["_offset:private"]=>
>>>>> int(-3600) ["_syncronised:private"]=> int(0) ["_dst:protected"]=> 
>>>>> bool(true)
>>>>> } }
>>>>>
>>>>>  See here the updated code:
>>>>> http://pastebin.com/m6cb13d9d
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Dec 30, 2009 at 6:19 PM, Hector Virgen <[email protected]>wrote:
>>>>>
>>>>>> It looks like you're adding the custom compareDates validator to both
>>>>>> date elements. It might be easier to just put it in one.
>>>>>>
>>>>>> If you can determine that $a < $b, then you already know that $b > $a.
>>>>>>
>>>>>> Also, in the $evtStartDate element, you are setting the field to
>>>>>> compare to $evtEndDate, which hasn't been created yet. Instead of 
>>>>>> passing in
>>>>>> the element, try passing in the element's field name "evt_enddate" (as a
>>>>>> string).
>>>>>>
>>>>>> I hope this helps.
>>>>>>
>>>>>> --
>>>>>> Hector
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, Dec 30, 2009 at 5:16 AM, Jigal sanders <[email protected]
>>>>>> > wrote:
>>>>>>
>>>>>>> Hello everyone,
>>>>>>>
>>>>>>>
>>>>>>> I have a form with two date fields. One startdate and one enddate. I
>>>>>>> want to make sure, the end date is not before the startdate.
>>>>>>> I am trying to create my own validator. Now i based my validator on
>>>>>>> this tutorial:
>>>>>>> http://cogo.wordpress.com/2008/04/16/custom-validators-for-zend_form_element/
>>>>>>> Here is my code: http://pastebin.com/f20aafd32  it's not yet ready.
>>>>>>>
>>>>>>> My problem is at line 52 where the value of  $this
>>>>>>> ->_fieldsToCompare is empty all the time.
>>>>>>> I also have problems in comparing the dates.
>>>>>>>
>>>>>>> Kan someone please help me along?
>>>>>>>
>>>>>>>
>>>>>>> <http://cogo.wordpress.com/2008/04/16/custom-validators-for-zend_form_element/>
>>>>>>>
>>>>>>> Kind regards,
>>>>>>>
>>>>>>> J. Sanders
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Met vriendelijke groet,
>>>>>
>>>>> Jigal Sanders
>>>>> A.J. Ernststraat 739
>>>>> 1082 LK Amsterdam
>>>>> Mobiel: 06-42111489
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Met vriendelijke groet,
>>>
>>> Jigal Sanders
>>> A.J. Ernststraat 739
>>> 1082 LK Amsterdam
>>> Mobiel: 06-42111489
>>>
>>
>>
>
>
> --
> Met vriendelijke groet,
>
> Jigal Sanders
> A.J. Ernststraat 739
> 1082 LK Amsterdam
> Mobiel: 06-42111489
>



-- 
Met vriendelijke groet,

Jigal Sanders
A.J. Ernststraat 739
1082 LK Amsterdam
Mobiel: 06-42111489

Reply via email to