Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony] problem z sfValidatorFile
Mgorka
post
Post #1





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

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


Witajcie właśnie uczę się tworzenia formu;arza w sf 1.4 i mam problem z validiatorem input type file mianowcie w jednym formularzu mi działa ok lecz gdy tworze następny na innej pod stronie to mimo iż podaję ścierzkę do pliku to validiator zwraca mi wartość Required w czym problem co robię nie tak dołączam kod:
  1. <?php
  2.  
  3. class OfertaForm extends BaseForm
  4. {
  5.  
  6. protected static $subjects = array('Subject A', 'Subject B', 'Subject C');
  7.  
  8. public function configure()
  9. {
  10. $this->setWidgets(array(
  11. 'message' => new sfWidgetFormTextarea(),
  12. 'file' => new sfWidgetFormInputFile(),
  13. ));
  14. $this->setDefaults(array('email' => 'Your Email Here', 'name' => 'Your Name Here'));
  15. $this->widgetSchema->setNameFormat('off[%s]');
  16. $this->setValidators(array(
  17. 'message' => new sfValidatorString(array('min_length' => 4), array('required' => 'The message field is required.')),
  18. 'file' => new sfValidatorFile(),
  19. ));
  20. }
  21. }

a teraz plik action
  1. public function executeOferta(sfWebRequest $request)
  2. {
  3. $this->form = new OfertaForm();
  4. //sprawdzanie poprawnosci wysłania
  5. if ($request->isMethod('post'))
  6. {
  7. $this->form->bind($request->getParameter('off'), $request->getFiles('off'));
  8. if ($this->form->isValid())
  9. {
  10. $file = $this->form->getValue('file');
  11.  
  12. $filename = '1';
  13. $extension = $file->getExtension($file->getOriginalExtension());
  14. $file->save(sfConfig::get('app_upload_oferta_dir').'/'.$filename.$extension);
  15. $this->file= http_build_query($this->form->getValues());
  16. $this->redirect('panel/addOferta?'.http_build_query($this->form->getValues()));
  17. }else{
  18. $this->redirect('oferta/addOferta?eror=valid');
  19. }
  20.  
  21. }
  22. }


Dostaje błąd przy walidjacji i versja dev pokazuje
Parameters:

$form (OfertaForm) Toggle details
$form['message'] (sfWidgetFormTextarea)
$form['file'] (sfWidgetFormInputFile)

Required.
$form['_csrf_token'] (sfWidgetFormInputHidden)
Ale sprawdzałem przesłane paramtry u token jest
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
mdco
post
Post #2





Grupa: Zarejestrowani
Postów: 324
Pomógł: 5
Dołączył: 14.12.2004

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


A jak wygląda plik szablonu?

Masz w znaczniku form enctype="multipart/form-data"?
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 23.08.2025 - 10:42