Mam standardowy zrobiony formularz
//apps/frontend/modules/sfGuardAuth/lib/form/rejestracjaForm.class.php <?php class rejestracjaForm extends sfForm { public function configure() { 'username' => new sfWidgetFormInput(), )); 'username' => new sfValidatorString(), )), )); $this->validatorSchema->setPostValidator( //new sfGuardValidatorUser(), new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password2', ) )) ); $this->widgetSchema->setNameFormat('rejestracja[%s]'); } public function getModelName() { return 'Rejestracja'; } } ?>
<?php ////apps/frontend/modules/sfGuardAuth/actions/action.class.php class sfGuardAuthActions extends BasesfGuardAuthActions { /** * Tworzy nowe konto użytkownikowi * * Metoda pozwala na zakladanie konta * * @return unknown */ public function executeRejestracja( sfWebRequest $request ) { $this->form = new rejestracjaForm(); } public function executeUpdate_rejestracja( sfWebRequest $request ){ $this->forward404Unless($request->isMethod('post') || $request->isMethod('put')); $this->form = new rejestracjaForm(); $this->processForm( $request, $this->form ); $this->setTemplate('rejestracja'); } protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $this->redirect( $this->generateUrl('homepage') ); } return false; } public function handleError() { return sfView::ERROR; } public function handleErrorUpdate_rejestracja() { return sfView::SUCCESS; } ?>
////apps/frontend/modules/sfGuardAuth/templates/rejestracjaSuccess.php <?php use_helper('Validation') ?> <h2>Rejestracja</h2> <table> </table> <?php ?> </form>
<?php ////apps/frontend/modules/sfGuardAuth/validate/update_rejestracja.yml methods: [post] validators: nicknameValidator: class: sfStringValidator param: min: 3 min_error: login musi miec minimum 5 znakow passwordValidator: class: sfStringValidator param: min: 5 min_error: haslo musi miec minimum 5 znakow newAccountValidator: class: myNewAccountValidator param: newaccount_error: login o tej nazwie już istnieje fields: names: username: required: msg: twoj login jest wymagany nicknameValidator: #newAccountValidator: password: required: msg: twoje haslo jest wymagane passwordValidator: password2: required: msg: twoje haslo jest wymagane passwordValidator: ?>
Reguły walidacji działają jedynie z klasy rejestracjaForm a nie są brane też pod uwage wpisy z /validate/*.yml
Szukałem na forum symfony lecz tam nawet przykładu podobnego do mojego nie znalazłem.
Ja wykorzystuje do generowania formularza klase sfForm i być może dlatego nie działają reguły walidacji z /validate/update_rejestracja.yml bo reguly walidacji pobiera z klasy rejestracjaForm,
Mi zależy aby można było wykorzystać własne walidatory np.
<?php /** * new account validator. * * @package askeet * @subpackage user * @author Your name here * @version SVN: $Id$ */ class myNewAccountValidator extends sfValidator { /** * Execute this validator. * * @param mixed A file or parameter value/array. * @param error An error message reference. * * @return bool true, if this validator executes successfully, otherwise * false. */ public function execute (&$value, &$error) { $this->getContext()->getRequest()->setAttribute('newaccount', true); $login = $value; $c = new Criteria(); $c->add(sfGuardUserPeer::USERNAME, $login); $user = sfGuardUserPeer::doSelectOne($c); // nickname exists? if ($user) { $error = $this->getParameterHolder()->get('newaccount_error'); return false; } return true; } public function initialize ($context, $parameters = null) { // initialize parent parent::initialize($context); // set defaults $this->getParameterHolder()->set('newaccount_error', 'Invalid input'); $this->getParameterHolder()->add($parameters); return true; } } ?>
Nie wiem w czym jest problem.