Note that there are some explanatory texts on larger screens.

plurals
  1. POisValid method is not working when using file element in form in zend framework
    text
    copied!<p>Form's code :</p> <pre><code> $companyName = new Zend_Form_Element_Text('company_name'); $companyName-&gt;setLabel('Company Name'); $companyName-&gt;setRequired(true); $companyName-&gt;setAttrib('size', 30) -&gt;setAttrib('class', 'required'); $companyDescription = new Zend_Form_Element_TextArea('company_description'); $companyDescription-&gt;setLabel('CompanyDescription') -&gt;setAttrib('cols', '10') -&gt;setAttrib('rows', '3') -&gt;setAttrib('style', 'resize: none;') -&gt;setAttrib('class', 'required'); $companyAddress = new Zend_Form_Element_Text('company_address'); $companyAddress-&gt;setLabel('Company Address'); $companyAddress-&gt;setRequired(true); $companyAddress-&gt;setAttrib('size', 30) -&gt;setAttrib('class', 'required'); $file = new Zend_Form_Element_File('uploaded_file'); echo PUBLIC_PATH; $file-&gt;setDestination(PUBLIC_PATH . '/fold/') -&gt;setLabel('File') -&gt;setRequired(true) -&gt;addValidator('NotEmpty'); $submit = new Zend_Form_Element_Submit('submit'); $submit-&gt;setAttrib('class', 'all-button'); $this-&gt;addElements(array($companyName, $companyDescription, $companyAddress,$file,$submit)); $this-&gt;setDecorators(array( 'FormElements', array('HtmlTag', array('tag' =&gt; 'table', 'id' =&gt; 'employees')), 'Form' )); $this-&gt;setElementDecorators(array( 'ViewHelper', array(array('data' =&gt; 'HtmlTag'), array('tag' =&gt; 'td', 'class' =&gt; 'odd')), array('Label', array('tag' =&gt; 'td')), array(array('row' =&gt; 'HtmlTag'), array('tag' =&gt; 'tr')) )); //Adding Browse $file-&gt;setDecorators(array( 'File', array(array('data' =&gt; 'HtmlTag'), array('tag' =&gt; 'td')), array('Label', array('tag' =&gt; 'td')), array(array('row' =&gt; 'HtmlTag'), array('tag' =&gt; 'tr')) )); $this-&gt;setDecorators(array('FormElements', array('HtmlTag',array('tag'=&gt;'table','id'=&gt;'employees1')),'Form')); $submit-&gt;setDecorators(array('ViewHelper', array(array('data' =&gt; 'HtmlTag'), array('tag' =&gt; 'td', 'class' =&gt; 'element')), array(array('emptyrow' =&gt; 'HtmlTag'), array('tag' =&gt; 'td', 'class' =&gt; 'element', 'placement' =&gt; 'PREPEND')), array(array('row' =&gt; 'HtmlTag'), array('tag' =&gt; 'tr')) )); </code></pre> <p>code for action addCompany:</p> <pre><code> public function addCompanyAction() { $userInfo = Zend_Auth::getInstance()-&gt;getStorage()-&gt;read(); $privilege_id = $userInfo-&gt;privilege_id; $this-&gt;view-&gt;privilege = $privilege_id; $form = new Company_Form_AddCompany(); $form-&gt;setMethod(Zend_Form::METHOD_POST) -&gt;setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART); $this-&gt;view-&gt;form = $form; if ($this-&gt;_request-&gt;isPost()) { //echo 'outside post'; $formData = $this-&gt;_request-&gt;getPost(); $location = $form-&gt;uploaded_file-&gt;getFileName(); var_dump($location); var_dump($formData); if ($form-&gt;isValid($formData)) { $company_name = $this-&gt;_getParam('company_name', 0); $company_des = $this-&gt;_getParam('company_description', 1); $company_addr = $this-&gt;_getParam('company_address', 2); if ($form-&gt;uploaded_file-&gt;receive()) { $location = $form-&gt;uploaded_file-&gt;getFileName(); echo 'Loc: '.$location.' '; $loc = PUBLIC_PATH . '/fold/'; if (rename($location, $loc . $company_name . '.jpg')) { $img_path = $loc . $company_name . '.jpg'; } else { $img_path =$location; } //Insert values in table $companyTable = new Project_Model_DbTable_Company(); $data = array( 'company_name' =&gt; $company_name, 'company_description' =&gt; $company_des, 'image_url' =&gt; $img_path, 'company_address' =&gt; $company_addr ); $object_company-&gt;insert($data); $message="Company added successfully"; } } else { echo 'else is Valid(): '; var_dump( $form-&gt;getMessages()); $form-&gt;populate($formData); } } } </code></pre> <p>code for view script add-company.phtml:</p> <pre><code> &lt;?php $this-&gt;headScript()-&gt;appendFile('/js/calendar_db.js', 'text/javascript'); $this-&gt;headLink()-&gt;prependStylesheet('/css/calendar.css'); $this-&gt;headScript()-&gt;appendFile('/js/validatious-custom-0.9.1.min.js', 'text/javascript'); ?&gt; &lt;div class ="menu"&gt; &lt;?php require_once '/Menus/setMenuDetails.php'; $privilege_id = $this-&gt;privilege; require_once setMenuDetails ::setMenuDetail($privilege_id); ?&gt; &lt;/div&gt; &lt;div class="page-title" align="center" &gt;Add New Company&lt;/div&gt; &lt;div class="back" title="Back" onclick="history.go(-1);" style="cursor: pointer; "&gt;&lt;/div&gt; &lt;form name="AddCompany" action="/Company/Company/add-company" method="post" class="validate"&gt; &lt;div class="profile-details" style="border: 0px solid red; height:700px;width:700px"&gt; &lt;table id="project"style="text-align: left; margin-top: 5px;" cellpadding="4" cellspacing="3" &gt; &lt;thead class ="tableHead"&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $this-&gt;form-&gt;company_name; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $this-&gt;form-&gt;company_description; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;?php echo $this-&gt;form-&gt;company_address; ?&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $this-&gt;form-&gt;uploaded_file; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;div class="shadow" style="height: 10px;margin-left:-200px;margin-top:20px"&gt; &lt;/div&gt; &lt;div class="page-title" align="center" style="margin-top:30px;margin-left:- 130px;height:20px;border: 0px solid aqua"&gt;--&gt; &lt;?php echo $this-&gt;form-&gt;submit; ?&gt; &lt;/tbody&gt; </code></pre> <p> </p> <p> </p> <p>problem is when I click submit button form data is not validated means if ($form->isValid($formData)) return false Why?? When I erase file part in form the form data is validated Help me...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload