tags:

views:

15

answers:

2

Hi, I've created a simple upload-form and got a little problem when submitting the data.

The file is uploaded correctly, but my little description field stays null.

Here's my form:

class Upload_Form_Uploadvideo extends Zend_Form{
public function init()
{
    $this->setName('video')
    ->setAction('interface/videoupload')
    ->setMethod('post');


    #id
    $id = new Zend_Form_Element_Hidden('id');
    $id->addFilter('Int');

    #Textfield "Videofile"
    $video = new Zend_Form_Element_File('videofile', array(
        'label'         => 'Videofile')
    );
    $video->setDestination(APPLICATION_PATH.'/upload/video/toConvert/');

    #Textfield "Videofile"
    $desc = new Zend_Form_Element_Text('videodescription', array(
        'label'         => 'Description')
    );
    $desc->setAttrib('value','The description is not optional!');
    $desc->setAttrib('size','25');


    #Submit
    $submit = new Zend_Form_Element_Submit('submit', array('label' => 'Upload Video'));
    $submit->setAttrib('id', 'submitbutton');


    #bringing everything together
    $this->addElements(array($id,$video,$desc,$submit));

    }
}

the controller, giving it to the view:

public function videouploadAction()
{
    #in production this code goes to the index()
    if(!$this->getRequest()->isPost()){
        return $this->_forward('index');
    }
    $form = $this->getForm();
    $this->view->via_getpost = var_dump($this->_request->getPost());

    $this->view->via_getvalues= var_dump($form->getValues());

}

Now, I var_dump $this->_request->getPost() and $form->getValues().

The output is the following:

array[$this->_request->getPost()]

'id' => string '0' (length=1)
'MAX_FILE_SIZE' => string '134217728' (length=9)
'videodescription' => string 'This is a test-video' (length=20)
'submit' => string 'Upload Video' (length=12)


array [$form->getValues()]

'id' => int 0
'videofile' => string 'swipeall.avi' (length=12)
'videodescription' => null

In addition, I set the "value"-attrib, without any effect. I intended to write something in the box, when the user loads the site.

I'm new to Zend, so I guess I'm just overseeing something stupid, though I can't find it.

Thx for your help

+1  A: 

use

$desc->setValue('The description is not optional!');

instead of

$desc->setAttrib('value','The description is not optional!');
kgb
Yeah, that solves the thing with the predefined text for the textfield, but now it always takes the value I set initally. I don't think, that I have to take the value of my textfield, which I want to write in a database, out of $_POST or something (at least I don't want to do this)
Frankie-T
Zend_Form can be used for building a form or for validating/getting form values. you have to use setValue() only when you build the form.Why don't you want to use $_POST? you can validate it using your form object to be sure: $form->isValid($_POST). (you have to add some validators to the form elements first)
kgb
A: 

k, I got it now. I really had to get the $_POST-Data via

$formdata = $this->getRequest()->getPost();

thx, kgb :)

Frankie-T