Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony]Problem z validiatorem file input
Mgorka
post 21.02.2012, 22:54:47
Post #1





Grupa: Zarejestrowani
Postów: 209
Pomógł: 3
Dołączył: 6.04.2010
Skąd: Słupca

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


Witajcie piszę formularz do uploadu wpisu wraz z zdjęciem do niego ale mam problem po mimo prawidłowego wypełnienia formularza validiator zwraca w polu file wartość required. Debuger pokazuje że przekazuje wszystkie dane wtaz z tokenem podaję pliki:
akcja
  1. public function executeDodajInformacje(sfWebRequest $request)
  2. {
  3. $this->form = new InformacjeForm();
  4. if ($request->isMethod('post'))
  5. {
  6. $this->form->bind($request->getParameter('informacje'), $request->getFiles('informacje'));
  7. if ($this->form->isValid())
  8. {
  9. $tytul = $this->form->getValue('tytul');
  10. $tresc = $this->form->getValue('tresc');
  11. $query = new Wiadomosci();
  12. $query -> setTytul($tytul);
  13. $query -> setTresc($tresc);
  14. $query -> setAutor($this->getUser()->getAttribute('name'));
  15. $query -> setData(date("Y-m-d"));
  16.  
  17. $query -> save();
  18. $id = $query->getWid();
  19. $this->krok = $id;
  20. $file = $this->form->getValue('file');
  21.  
  22. $filename = '1';
  23. $extension = $file->getExtension($file->getOriginalExtension());
  24. $file->save(sfConfig::get('app_upload_oferta_dir').'/'.$filename.$extension);
  25. }
  26. }
  27. }


formularz
  1. <?php
  2.  
  3. class InformacjeForm extends BaseForm
  4. {
  5. protected static $subjects = array('Subject A', 'Subject B', 'Subject C');
  6.  
  7. public function configure()
  8. {
  9. $this->setWidgets(array(
  10. 'tytul' => new sfWidgetFormInputText(),
  11. 'dzial' => new sfWidgetFormSelect(array('choices' => self::$subjects)),
  12. 'tresc' => new sfWidgetFormTextarea(),
  13. 'file' => new sfWidgetFormInputFile(),
  14. ));
  15. $this->widgetSchema->setNameFormat('informacje[%s]');
  16. $this->setValidators(array(
  17. 'tytul' => new sfValidatorString(),
  18. 'dzial' => new sfValidatorChoice(array('choices' => array_keys(self::$subjects))),
  19. 'tresc' => new sfValidatorString(array('min_length' => 4), array('required' => 'The message field is required.')),
  20. 'file' => new sfValidatorFile(),
  21. ));
  22. }
  23. }
Go to the top of the page
+Quote Post
Valantir
post 22.02.2012, 00:48:05
Post #2





Grupa: Zarejestrowani
Postów: 93
Pomógł: 7
Dołączył: 6.09.2011
Skąd: Olsztyn

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


Kod
'file'  => new sfValidatorFile(array(
   'max_size'              =>  8192000,
   'mime_types'            =>  'web_images',
   'path'                  =>  'gdzie_zapisać_plik',
   'validated_file_class'  =>  'sfValidatedFile', //klasa walidująca
   'required'              =>  true
), array(
   'max_size'              =>  'Wielkośc pliku nie może przekroczyś 8 MB',
   'mime_types'            =>  'Akceptowalne pliki to GIF, JPG i PNG',
   'required'              =>  'Pole jest wymagane'
)),


Pisane szybko i nie sprawdzane więc spróbuj, a ja tym czasem idę spaćtongue.gif


--------------------
Pomogłem? Kliknij "Pomógł".
Go to the top of the page
+Quote Post
Mgorka
post 22.02.2012, 09:59:31
Post #3





Grupa: Zarejestrowani
Postów: 209
Pomógł: 3
Dołączył: 6.04.2010
Skąd: Słupca

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


No właśnie twojej metody też próbowałem no i nic nie pomogło ;/
Go to the top of the page
+Quote Post
Valantir
post 22.02.2012, 13:18:28
Post #4





Grupa: Zarejestrowani
Postów: 93
Pomógł: 7
Dołączył: 6.09.2011
Skąd: Olsztyn

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


Na bank w debuggerze nic nie pokazuje? Skoro wyświetla required to musi coś być... Sprawdź w logach może i z tego co pamiętam to nie wiem czy w Firebugu nie można sprawdzić czy jest wysyłany obrazek...


--------------------
Pomogłem? Kliknij "Pomógł".
Go to the top of the page
+Quote Post
Mgorka
post 22.02.2012, 14:20:56
Post #5





Grupa: Zarejestrowani
Postów: 209
Pomógł: 3
Dołączył: 6.04.2010
Skąd: Słupca

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


Debuger pokazuje że pilk był wysłany w post:
" post: informacje: { tytul: siema, dzial: '1', tresc: asdasd, file: DSCF5004.JPG, _csrf_token: 77031d0908d48cecfeb605b2da1043d0 }"
A jakiś plik konfiguracyjny jest tak jak by powiązany z walidem

Ten post edytował Mgorka 22.02.2012, 14:21:46
Go to the top of the page
+Quote Post
jaro87
post 22.02.2012, 14:26:10
Post #6





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

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


Oczywiście formularz wysyłasz z enctype="multipart/form-data" ?

Cytat(Mgorka @ 22.02.2012, 14:20:56 ) *
Debuger pokazuje że pilk był wysłany w post


On chyba pokazuje, że jakiś string został podany w inpucie a nie, że przesłano plik tongue.gif

Ten post edytował jaro87 22.02.2012, 14:31:19
Go to the top of the page
+Quote Post
janek9
post 22.02.2012, 17:47:52
Post #7





Grupa: Zarejestrowani
Postów: 121
Pomógł: 2
Dołączył: 22.03.2009

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


Pokaz nam templatke z formularzem
Go to the top of the page
+Quote Post
Mgorka
post 23.02.2012, 09:56:22
Post #8





Grupa: Zarejestrowani
Postów: 209
Pomógł: 3
Dołączył: 6.04.2010
Skąd: Słupca

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


ok poprawione brakowało w from 3 słów;p
Go to the top of the page
+Quote Post
MariuszS
post 15.10.2012, 11:50:40
Post #9





Grupa: Zarejestrowani
Postów: 23
Pomógł: 0
Dołączył: 14.09.2004
Skąd: Radom

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


To może podaj rozwiązanie na przyszłość dla ludzi którzy spotkają się z podobnym problemem...
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 Wersja Lo-Fi Aktualny czas: 4.06.2024 - 23:25