I use symfony 1.4.8 . I add ReCaptcha to my form , using SfExtraFormPlugin. I have widget and validator for it in my " public function configure() "
....
$this->widgetSchema['captcha'] = new sfWidgetFormReCaptcha(array(
'public_key' => sfConfig::get('app_recaptcha_public_key')
));
$this->validatorSchema['captcha'] = new sfValidatorReCaptcha(array(
'private_key' => sfConfig::get('app_recaptcha_private_key')
));
...
I also have bac开发者_C百科kend app , and my "public function configure()" for it :
public function configure()
{
parent::configure();
....
}
So when I want to add post from my backend I have an error:The item has not been saved due to some errors. Is there a way to remove widget and validators for ReCaptcha only to my backend? Now I see only one way, it is to remove
parent::configure();
and write all widget and validators to backend separately from the frontend widget and validators.. :( p.s Sorry for my bad English p.p.s Thank you in advance for your answers ;-)
Add an option to your form. When you instantiate it, you should know if you're on the backend or the frontend.
// in your actions.class.php
$this->form = new MyForm(null, array('from_backend' => true)); // or false...
// in your form
if (!$this->getOption('from_backend'))
{
// add the recaptcha widget and validator...
}
It should work :)
I find second way :
if ( sfConfig::get('sf_app') == "frontend" )
{
widget and validator
}
elseif ( sfConfig::get('sf_app') == "backend" )
{
widget and validator
}
精彩评论