Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony] Nowy Validator - brak wiadomosći
Micchaleq
post
Post #1





Grupa: Zarejestrowani
Postów: 186
Pomógł: 4
Dołączył: 13.10.2009

Ostrzeżenie: (0%)
-----


Witam serdecznie,

Postanowiłem całkowicie zmienić swój post ponieważ problem w większości został roziwązany.

W większości dlatego, że teraz jak błąd wyświetla mi się jedynie wartość jaką przypiszę a nie wiadomość ktróą zdeklarowałem

  1. <?php
  2.  
  3.  
  4. class sfValidatorDefaultString extends sfValidatorString{
  5.  
  6. protected function configure($options = array(), $messages = array())
  7. {
  8. parent::configure($options, $messages);
  9.  
  10. $this->addMessage('default_string', 'Poniższe pole nie może być wysłane z domyślną wartością.');
  11.  
  12. $this->addOption('default_string');
  13. }
  14. protected function doClean($value)
  15. {
  16. $clean = parent::doClean($value);
  17.  
  18. // tutaj utknąłem
  19. if(in_array($value, $this->getOptions('default_string')))
  20. {
  21. throw new sfValidatorError($this, 'default_string', array('value' => $value['name'], 'default_string' => $this->getOption('default_string')));
  22. }
  23.  
  24. return $clean;
  25. }
  26. }
  27.  
  28. ?>


a w formie deklaruje to tak


  1. 'nazwa' => new sfValidatorDefaultString(array(), array('required' => 'Pole imie i nazwisko jest wymagane.', 'default_string' => '(imię i nazwisko)')),


Ten post edytował Micchaleq 17.04.2012, 10:35:00


--------------------
Go to the top of the page
+Quote Post
jaro87
post
Post #2





Grupa: Zarejestrowani
Postów: 53
Pomógł: 7
Dołączył: 10.03.2011
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Spójrz na walidator. W konstruktorze pierwszy parametr to 'options', drugi to 'messages'. W swoim formularzu nadpisujesz wiadomość dla 'default_string' stringiem '(imię i nazwisko)', powinieneś mieć coś takiego:

  1. $this->validatorSchema['nazwa'] = new sfValidatorDefaultString(array('default_string' => '(imię i nazwisko)'), array('required' => 'Pole imie i nazwisko jest wymagane.'));


Druga sprawa to
  1. if(in_array($value, $this->getOptions('default_string'))){...}


tu raczej powinieneś zrobić
  1. if($value == $this->getOption('default_string')){...}


Ten post edytował jaro87 17.04.2012, 14:11:27
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 04:44