I looked at your tutorial for Zend_Form_Element_File but I just don’t know how to use it can you send me a newer version where the form is seperated with the controller. below is a form, controller and view sample but I can’t seem to make setDestination work The given destination is no directory or does not exist. where does it save the file my controller is upload action is index. what is the url (root/upload/index/data)? PLEASE HELP.
/////////
// zend form class
/////////
class UploadForm extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName(‘upload’);
$this->setAttrib(‘enctype’, ‘multipart/form-data’);
$description = new Zend_Form_Element_Text(‘description’);
$description->setLabel(‘Description’)
->setRequired(true)
->addValidator(‘NotEmpty’);
$file = new Zend_Form_Element_File(‘file’);
$file->setLabel(‘File’)
->setDestination(‘/data’)
->setRequired(true);
$submit = new Zend_Form_Element_Submit(‘submit’);
$submit->setLabel(‘Upload’);
Ahsan, thank you for this masterful tutorial. My question is after you created the module, how do you implement it on a page so that it can be used for searches. That’s my main issue right now. As far as presentation, I can take care of it. Thanks in advance.
Hi,
I looked at your tutorial for Zend_Form_Element_File but I just don’t know how to use it can you send me a newer version where the form is seperated with the controller. below is a form, controller and view sample but I can’t seem to make setDestination work The given destination is no directory or does not exist. where does it save the file my controller is upload action is index. what is the url (root/upload/index/data)? PLEASE HELP.
/////////
// zend form class
/////////
class UploadForm extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName(‘upload’);
$this->setAttrib(‘enctype’, ‘multipart/form-data’);
$description = new Zend_Form_Element_Text(‘description’);
$description->setLabel(‘Description’)
->setRequired(true)
->addValidator(‘NotEmpty’);
$file = new Zend_Form_Element_File(‘file’);
$file->setLabel(‘File’)
->setDestination(‘/data’)
->setRequired(true);
$submit = new Zend_Form_Element_Submit(‘submit’);
$submit->setLabel(‘Upload’);
$this->addElements(array($description, $file, $submit));
}
}
/////////////
//controller
/////////////
view->headTitle(‘Home’);
$this->view->title = ‘Zend_Form_Element_File Example’;
$this->view->bodyCopy = “Please fill out this form.”;
$form = new UploadForm();
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
// success – do something with the uploaded file
$uploadedData = $form->getValues();
$fullFilePath = $form->file->getFileName();
Zend_Debug::dump($uploadedData, ‘$uploadedData’);
Zend_Debug::dump($fullFilePath, ‘$fullFilePath’);
echo “done”;
exit;
} else {
$form->populate($formData);
}
}
$this->view->form = $form;
}
}
/////////////
// index.phtml
/////////////
title; ?>
bodyCopy; ?>
form; ?>
Ahsan, thank you for this masterful tutorial. My question is after you created the module, how do you implement it on a page so that it can be used for searches. That’s my main issue right now. As far as presentation, I can take care of it. Thanks in advance.
Asalamu Alikum
Dear Respected Sir, i need some Help in PHp Please Can u help me , i m from lahore aplease it request