None of these answers explain how to remove the โCSRF token:โ label, which prefixes the error message in an inactive way (for example, changing the token name is a bad idea!).
The only audible way to remove a tag is to extend the CSRF authentication to cause a global error. While we are doing this, we can also change the error message.
class myValidatorCSRFToken extends sfValidatorCSRFToken { protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->addMessage('csrf_attack', 'Your session has expired. Please return to the home page and try again.'); } protected function doClean($value) { try { return parent::doClean($value); } catch (sfValidatorError $e) { throw new sfValidatorErrorSchema($this, array($e)); } } }
Now, so that our forms use this validator by overriding sfForm::addCSRFProtection in BaseForm :
public function addCSRFProtection($secret = null) { parent::addCSRFProtection($secret); if (isset($this->validatorSchema[self::$CSRFFieldName]))
Jeremy kauffman
source share