0

must be some thing simply resolving, but as a beginner, i've already spend 2 days trying to find out. I'm having a simple form ("enctype="multipart/form-data") with few inputs of text and file. I can't get what's wrong, i can get user's text data through getParameter(), but cannot get file getFiles(). i'm on ubuntu 11.04 php5.3

code:

form class:

public function configure()
  {
    $this->setWidgets(array(
      'vendor'  => new sfWidgetFormInputText(array(), array('class' => 'form-text')),
      'image'       => new sfWidgetFormInputFile(array(), array('class' => 'form-text')),
      'city'      => new sfWidgetFormInputText(),
      'email'   => new sfWidgetFormInputText(array('default' => 'simple@sample.org')),
        'contacts' => new sfWidgetFormTextarea(),
      'description' => new sfWidgetFormTextarea(),
    ));
    $this->setValidators(array(
      'vendor'  => new sfValidatorString(array('required' => false)),
        'image'   => new sfValidatorFile(array(
            'required'  => false,
        'path'       => sfConfig::get('sf_upload_dir') . '/images',
        'mime_types' => 'web_images')),
      'city'    => new sfValidatorString(array('required' => false)),
        'email' => new sfValidatorString(array('required' => false)),
        'contacts'  => new sfValidatorString(array('required' => false)),
        'description'   => new sfValidatorString(array('required' => false)),
    ));
    $this->widgetSchema->setNameFormat('pv[%s]');
  }

action:

public function executeCreate(sfWebRequest $request)
{
$this->forward404Unless($request->isMethod(sfRequest::POST));
return $this->renderText(var_dump($request->getParameter('pv'))); //this array include vars from form
//return $this->renderText(var_dump($request->getFiles('pv'))); //empty array
}
bduisenov
  • 3
  • 1
  • 3
  • ok, I understood my problem, I was using jq plugin and submit button was jq_submit_to_remote() which was not acting as I supposed to. – bduisenov Apr 29 '11 at 04:58

4 Answers4

0

You should provide the actual code you are trying with. You could also look further into the forms component, which has a section on file uploads with example code here (bottom of page):

http://www.symfony-project.org/forms/1_2/en/02-Form-Validation

This part of the docs is still relevant for symfony 1.4.

Gerry
  • 6,012
  • 21
  • 33
0

Does your form widget configuration look anything like the following?

$this->setWidget('attachment', new sfWidgetFormInputFileEditable(array(
  'file_src' => '/upload/' . $this->getObject()->getAttachment(),
  'edit_mode' => true,
  'with_delete' => true,
)));

$this->setValidator('attachment', new sfValidatorFile(array(
  'path' => sfConfig::get('sf_upload_dir'),
  'required' => false
)));
$this->setValidator('attachment_delete', new sfValidatorPass());

Also, check if you have permissions on your upload folder:

chmod 777 web/upload/
Dziamid
  • 11,225
  • 12
  • 69
  • 104
0

Are you binding the files as well as the form parameters, like so?

$this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
matt
  • 1,947
  • 1
  • 19
  • 29
-1

you must add the enctype="multipart/..." attribute to your form

sage
  • 1
  • 1
  • 1
    Try to read the question before you answer ;-) He says the he has the multipart attribute in his form. – Tankhenk May 22 '13 at 09:37