test
Returns TRUE if and only if $value contains only alphabetic and digit characters. This validator includes an option to also consider white space characters as valid.
class DocumentForm extends Zend_Form
{
function addAction()
{
$form = new DocumentForm();
$this->view->form = $form;
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
/* Uploading Document File on Server */
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->setDestination("/uploads/files/");
try {
// upload received file(s)
$upload->receive();
} catch (Zend_File_Transfer_Exception $e) {
$e->getMessage();
}
// so, Finally lets See the Data that we received on Form Submit
$uploadedData = $form->getValues();
Zend_Debug::dump($uploadedData, 'Form Data:');
// you MUST use following functions for knowing about uploaded file
# Returns the file name for 'doc_path' named file element
$name = $upload->getFileName('doc_path');
# Returns the size for 'doc_path' named file element
# Switches of the SI notation to return plain numbers
$upload->setOption(array('useByteString' => false));
$size = $upload->getFileSize('doc_path');
# Returns the mimetype for the 'doc_path' form element
$mimeType = $upload->getMimeType('doc_path');
// following lines are just for being sure that we got data
print "Name of uploaded file: $name
";
print "File Size: $size
";
print "File's Mime Type: $mimeType";
// New Code For Zend Framework :: Rename Uploaded File
$renameFile = 'newName.jpg';
$fullFilePath = '/images/'.$renameFile;
// Rename uploaded file using Zend Framework
$filterFileRename = new Zend_Filter_File_Rename(array('target' => $fullFilePath, 'overwrite' => true));
$filterFileRename -> filter($name);
exit;
}
} else {
// this line will be called if data was not submited
$form->populate($formData);
}
}
}
Release Better Code Sooner, Increase Developer Productivity
Example #4 Setting Filters for All Elements
In some cases, you may want to apply the same filter to all elements; a common case is to trim() all values: