2

I've made complex form which is valid in action. I'd like to get value from this input to save file on server.

<input type="text" 
    name="produkty[pForm][1][caption]" 
    id="produkty_pForm_1_caption" />

I've tried something like that:

$this->form=new ProduktyForm();

if ($request->isMethod(sfRequest::POST))
{
   $this->form->bind($request->getParameter('produkty'),$request->getFiles('produkty'));
   if ( $this->form->isValid())
   {
       $file=$this->form->getValue('produkty[pForm][1][src]');
       $filename='u';
       $extension = $file->getExtension($file->getOriginalExtension());
       $file->save(sfConfig::get('sf_upload_dir').'/'.$filename.$extension);
   }
}

But it doesn't work.

1
  • "It doesn't work" is usually always an insufficient error description. Commented Dec 26, 2011 at 16:37

2 Answers 2

4

'produkty' is the name of your form. Are you using a subform to capture an array of possible files to be input?

You could get the values of the entire form by doing this.

$form_vals = $this->form->getValues();

Then you could could see what variables you have by your output.

You'll probably be able to get the input this way.

$caption = $form_vals['pForm'][1]['caption']; 

this is working fine but how to fetch the values from file attributes . i cant get the values from file input my main form name is slide and subform is mslide

here is the my code

$this->multiSlideForm->bind($request->getParameter('slide'), $request->getFiles('slide'));
$form_vals = $this->multiSlideForm->getValues();
echo $form_vals['mslide'][0]['slide_name']; //working
echo $this->multiSlideForm->getValue('[mslide][0][file_name]')->getOriginalName();  //not working  
Sign up to request clarification or add additional context in comments.

Comments

0

In my case, I'm using Symfony <3 , legacy version, and form.getObject.getReplyTypeId works for me, replace getReplyTypeId with the getter of any property you may need from the object

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.