mam problem z zabindowaniem formularza oraz z jednym polem podczas walidacji mam takie formularze :
<?php
/**
* Uzytkownicy form base class.
*
* @package serwis
* @subpackage form
* @author Your name here
* @version SVN: $Id: sfPropelFormGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
*/
class BaseUzytkownicyForm extends BaseFormPropel
{
public function setup()
{
'usid' => new sfWidgetFormInputHidden(),
'login' => new sfWidgetFormInput(),
'haslo' => new sfWidgetFormInputPassword(),
'imie' => new sfWidgetFormInput(),
'nazwisko' => new sfWidgetFormInput(),
'miasto' => new sfWidgetFormInput(),
'mail' => new sfWidgetFormInput(),
'osobie' => new sfWidgetFormInput(),
'data_2' => new sfWidgetFormDate(),
'usuniety' => new sfWidgetFormInput(),
));
$this->setValidators(array( 'usid' => new sfValidatorPropelChoice
(array('model' => 'Uzytkownicy', 'column' => 'usid', 'required' => false)), 'login' => new sfValidatorString
(array('max_length' => 255, 'required' => true)), 'haslo' => new sfValidatorString
(array('max_length' => 45, 'required' => true)), 'imie' => new sfValidatorString
(array('max_length' => 255, 'required' => true)), 'nazwisko' => new sfValidatorString
(array('max_length' => 255, 'required' => true)), 'miasto' => new sfValidatorString
(array('max_length' => 255, 'required' => true)), 'mail' => new sfValidatorEmail
(array('required' => true)), 'osobie' => new sfValidatorString
(array('max_length' => 255, 'required' => false)), 'data_2' => new sfValidatorDate
(array('required' => false)), 'usuniety' => new sfValidatorInteger(),
));
$this->validatorSchema->setPostValidator(
new sfValidatorPropelUnique
(array('model' => 'Uzytkownicy', 'column' => array('login'))) );
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
parent::setup();
}
public function getModelName()
{
return 'Uzytkownicy';
}
}
?>
<?php
class RejestracjaForm extends BaseUzytkownicyForm {
public function configure() {
unset($this['usuniety'],$this['miasto'],$this['osobie'],$this['data_2'],$this['usid']); $this->setWidget('powtorz',new sfWidgetFormInputPassword());
$this->setValidator('powtorz',new sfValidatorString
(array('max_length' => 45, 'required' => true))); $this->widgetSchema->moveField('powtorz',sfWidgetFormSchema::AFTER,'haslo');
[b]$this->widgetSchema->setNameFormat('register[%s]');[/b]
$this->widgetSchema->setFormFormatterName('list');
$this->validatorSchema->setPostValidator(
new sfValidatorSchemaCompare('haslo','==','powtorz'));
}
}
?>
<?php
/**
* rejestracja actions.
*
* @package serwis
* @subpackage rejestracja
* @author Your name here
* @version SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
*/
class rejestracjaActions extends sfActions
{
/**
* Executes index action
*
* @param sfRequest $request A request object
*/
public function executeIndex(sfWebRequest $request)
{
$this->form=new RejestracjaForm();
if ($request->isMethod('post')) {
// $this->form->bind(array('login'=>$this->getRequest()->getParameter('login'),
// 'haslo'=>$request->getParameter('haslo'),
// 'powtorz'=>$this->getRequest()->getParameter('powtorz'),
// 'imie'=>$this->getRequest()->getParameter('imie'),
// 'nazwisko'=>$this->getRequest()->getParameter('nazwisko'),
// 'mail'=>$this->getRequest()->getParameter('mail'),
// ));
[b] $this->form->bind($request->getParameter('register'));[/b]
if ($this->form->isValid()) {
$this->form->save();
$this->redirect('rejestracja/dziekujemy');
}
}
}
public function executeDziekujemy(sfWebRequest $request) {
$this->setTemplate('dziekuje');
}
}
?>
Otóz jeśli binduje formularz w ten sposób, który jest zakomentowany to wszytsko jest ok, ale czy nie ma jakiegoś szybszego sposobu takiego jak ta linijka wytłuszczona. Jak chce tak zrobic to niestety wyskakuje błąd :
Catchable fatal error: Argument 1 passed to sfForm::bind() must be an array ... (co oczywiscie sygnalizuje ze wymaga jako arg. tablicy. Jeszcze z czym mam problem to
<?php
$this->validatorSchema->setPostValidator(
new sfValidatorPropelUnique
(array('model' => 'Uzytkownicy', 'column' => array('login'))) );
?>
ten walidator nie działa nie mam pojęcia dlaczego.
Aha jescze jedno pytanko jak odnieść się do takiego pola podczas bindowania
$this->widgetSchema->setNameFormat('register[%s]'); bo jak próbuję 'mail'=>$this->getRequest()->getParameter('register[mail]') to nie działa