Reusing form validators in isolation

Sometimes you need to validate a specific data using a form validator.

Instead of binding the entire form, let’s just use the existing validator of the field we want to update :

try
{
  $product = ProductPeer::retrieveByPk($request->getParameter(‘id‘);
  $this->form = new sfProductForm($product);

  $validators = $this->form->getValidatorSchema();

  // Get the validator for the ‘name’ field and clean/validate input
  $clean_name = $validators['name']->clean($request->getParameter(‘name‘);
  
  echo ’ok‘;
}
catch (sfValidatorError $e)
{
  $e->getMessage();
} 
Advertisements



    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s



%d bloggers like this: