Hey!

I don't know what I'm doing wrong. I implemented a file upload in a
"complex" form and it didn't work. So I created a simple testform to
test the file upload:

Upload.class.php

class Upload extends sfForm
{

  public function configure()
  {

    $this->setWidget("image", new sfWidgetFormInputFile());

    # define validator for image
    $configData = sfConfig::get("app_job_image");

    $this->setValidator("image", new sfValidatorFile(array(
        "required"  => true,
        "path"  => sfConfig::get('sf_upload_dir') . $configData
['upload_dir'] ,
        "mime_types"  => array('image/jpeg', 'image/jpg'),
        "max_size"  => $configData['max_size'] * 1024
    ), array(
        "mime_types"  =>  "Es werden nur Bilder im JPEG-Dateiformat
unterstützt",
        "max_size"  =>  "Dein ausgewähltes Bild ist zu groß (maximal ".
$configData['max_size']." Kilobyte)"
    )));

    $this->widgetSchema->setNameFormat('upload[%s]');

  }

}


My action:

$this->form = new Upload();

    if($request->isMethod('post')) {
      $this->form->bind($request->getParameter($this->form->getName
()), $request->getFiles($this->form->getName()));

      if($this->form->isValid())
      {
        var_dump($this->form['image']->getValue());
      }
    }

My template:

<form action="<?php echo url_for("@upload") ?>" method="post"
enctype="multipart/form-data">
    <?php echo $form['image']->renderLabel(null, array("class" =>
"input")) ?>
    <?php echo $form['image']->render() ?>
    <?php echo $form['image']->renderError() ?>
    <input type="submit">
</form>


$this->form['image']->getValue() returns NULL if the form is valid. I
don't get it .. It should return a sfValidatedFile object .. where is
my mistake?

Thanks guys ..
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to