I actually turned this into a little class file.

<?php

class ConditionalValidatorManager{

        private $conditionalParams = array();
        private $sfAction = null;
        
        public function __construct($sfAction, $params)
        {
                $this->conditionalParams = $params;
                $this->sfAction = $sfAction;
        }

        public function setConditionParameter($checksum=null,  
$validatorName=null)
        {
                $this->conditionalParams[$checksum] = $validatorName;
        }
        
        public function doValidate($checksum=null)
        {
                if(!array_key_exists($checksum, $this->conditionalParams)) 
return  
true;

         $validated = true;
         $validationConfig = $this->sfAction->getModuleName() . '/' .
                                                                                
sfConfig::get('sf_app_module_validate_dir_name') . '/' .
                                                                                
$this->conditionalParams[$checksum] . '.yml';

         if (null !== $validateFile = sfConfigCache::getInstance()- 
 >checkConfig(sfConfig::get('sf_app_module_dir_name')
                                                                                
                                                                                
. '/' . $validationConfig, true))
         {
             $context = $this->sfAction->getContext();
             $validatorManager = new sfValidatorManager();
             $validatorManager->initialize($context);
             require($validateFile);
             $validated = $validatorManager->execute();
        }

         return $validated;             
        }
}

?>


To implement it it's something like this.  No need for a  
handleErrorXXXXXX() function in this case.



        $validationManager = new ConditionalValidatorManager($this, array(
                                                                                
                                                        'newcc' =>      
'checkout_newcc',
                                                                                
                                                        'cof'   =>      
'checkout_cof'
                                                                                
                                                        ));

        // The parameter passed into the doValidate method is your  
conditional value, so if you have 2 radio buttons it's value
        // would be passed into doValidate,
        $validationsResult = $validationManager->doValidate('newcc');           
// use  
checkout_newcc.yml for validations

        or

        $validationsResult = $validationManager->doValidate('cof');             
// use  
checkout_cof.yml for validations

        // On the post do some processing and redirect.
        if ($validationsResult && $this->getRequest()->getMethod() ==  
sfRequest::POST)
        {
                validated.

        }

        





On May 29, 2008, at 3:09 PM, forkmantis wrote:

>
> Razvan,
>
> What I've done for cases like this is use this snippet, which allows
> you to use conditional logic to load validation yaml:
>
> http://www.symfony-project.org/snippets/snippet/232
>
> So I make a standard validation file for the common validation that
> needs to happen for both edits and creates, and then I use if/then
> logic to load additional validation files needed for creating a
> record.
>
> On May 29, 1:21 pm, Razvan Popa <[EMAIL PROTECTED]> wrote:
>> Hello.
>> What would be a good practice in separating the validating  
>> procedure for
>> the action update depending on who's invoking it ... create or edit?
>>
>> Basically I have this situation. I'm trying to ensure that a  
>> username is
>> unique. I only allow the user to enter a username from the create  
>> action.
>> So it should be required and validated only for the create action.  
>> It is
>> required for the edit too but I don't want it to run the unique
>> vaildator when editing. I don't allow the user to update the  
>> username in
>> the update action anyway.  By the way I can't use the propel unique
>> validator because of a certain element in the generation of the  
>> username.
>>
>> Cheers,
>> --
>> Razvan
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to