/** * Overridden isValid() method for pre-validation code * * @param array $formData data typically from a POST or GET request * * @return bool */ public function isValid($formData = array()) { // If the ASN, Name and Town are all entered - the form is technically // valid - but we need to check to make sure the ASN is actually a // valid one. if (isset($formData['letting_agent_asn']) && $formData['letting_agent_asn'] != '') { $agentDatasource = new Datasource_Core_Agents(); $agent = $agentDatasource->getDetailsByASN($formData['letting_agent_asn']); if (count($agent) == 0) { // Call the parent isValid to generate other error messages parent::isValid($formData); $this->getElement('letting_agent_asn')->addError('Not a valid Agent Scheme Number'); // Return invalid return false; } } // Check if letting_agent_agent is 'Yes', if so then either: // letting_agent_name AND letting_agent_town are mandatory, OR // letting_agent_asn is mandatory if (isset($formData['have_letting_agent']) && $formData['have_letting_agent'] == 'yes') { // Set all three to mandatory first $this->getElement('letting_agent_name')->setRequired(true); $this->getElement('letting_agent_town')->setRequired(true); $this->getElement('letting_agent_asn')->setRequired(true); // Decide which can be un-mandatory if (trim($formData['letting_agent_asn']) != '') { $this->getElement('letting_agent_name')->setRequired(false); $this->getElement('letting_agent_town')->setRequired(false); } if (trim($formData['letting_agent_name']) != '' && trim($formData['letting_agent_town']) != '') { $this->getElement('letting_agent_asn')->setRequired(false); } } elseif (isset($formData['have_letting_agent']) && $formData['have_letting_agent'] == 'no') { // The user has said they don't have a letting agent so ignore all the validation // TODO: This is a dirty fix to QC4364 - this code is so complex and dirty that I can't actually find // why it's throwing weird haystack validation errors. Needs re-factoring. return true; } // Call original isValid() return parent::isValid($formData); }
/** * Gets the details for a specific agent * * @return void */ public function getagentdetailsAction() { $output = array(); $request = $this->getRequest(); $postdata = $request->getPost(); $agentLookup = new Datasource_Core_Agents(); $output['data'] = $agentLookup->getDetailsByASN($postdata['letting_agent_asn']); $output['errorJs'] = ''; $output['errorCount'] = 0; $output['errorHtml'] = ''; echo Zend_Json::encode($output); }