public function addGuarantors($formData) { for ($i = 1; $i <= $formData['total_guarantors']; $i++) { // Add guarantor name element $this->addElement('text', 'guarantor_name_' . $i, array('label' => 'Full name', 'required' => true, 'filters' => array('StringTrim'), 'maxlength' => '80', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please enter guarantor {$i}'s name", 'notEmptyInvalid' => "Please enter guarator {$i}'s name")))))); // Guarantor Home Telno $this->addElement('text', 'guarantor_hometelno_' . $i, array('label' => 'Home telephone number', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please enter guarantor {$i}'s home telephone number", 'notEmptyInvalid' => "Please enter guarantor {$i}'s home telephone number")))))); // Guarantor Work Telno $this->addElement('text', 'guarantor_worktelno_' . $i, array('label' => 'Work telephone number', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please enter guarantor {$i}'s work telephone number", 'notEmptyInvalid' => "Please enter guarantor {$i}'s work telephone number")))))); // Guarantor Mobile Telno $this->addElement('text', 'guarantor_mobiletelno_' . $i, array('label' => 'Mobile number', 'required' => false, 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please enter guarantor {$i}'s mobile telephone number", 'notEmptyInvalid' => "Please enter guarantor {$i}'s mobile telephone number")))))); if ($formData['guarantor_mobiletelno_' . $i] == '' && $formData['guarantor_hometelno_' . $i] == '') { $this->getElement('guarantor_mobiletelno_' . $i)->setRequired(true); $this->getElement('guarantor_hometelno_' . $i)->setRequired(true); } // Guarantor Email $this->addElement('text', 'guarantor_email_' . $i, array('label' => 'Email address', 'required' => false, 'filters' => array('StringTrim'), 'maxlength' => '50', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please enter guarantor {$i}'s email address", 'notEmptyInvalid' => "Please enter guarantor {$i}'s email address")))))); // Add guarantor postcode $this->addElement('text', 'guarantor_postcode_' . $i, array('label' => 'Postcode', 'required' => true, 'filters' => array('StringTrim'), 'maxlength' => '10', 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please enter guarantor {$i}'s postcode", 'notEmptyInvalid' => "Please enter guarantor {$i}'s postcode"))), array('regex', true, array('pattern' => '/^[0-9a-z]{2,}\\ ?[0-9a-z]{2,}$/i', 'messages' => "Guarantor {$i}'s postcode must be in postcode format"))))); // Add the find address button $this->addElement('submit', 'address_lookup_' . $i, array('ignore' => true, 'class' => 'lookupbutton', 'onclick' => 'getPropertiesByPostcode($(\'#guarantor_postcode_' . $i . '\').val(), \'guarantor_postcode_' . $i . '\', \'guarantor_address_' . $i . '\',\'guarantor_child_' . $i . '\'); return false;')); $this->getElement('address_lookup_' . $i)->removeDecorator('label'); // Add hidden element for postcode $this->addElement('hidden', 'guarantoraddress_id_' . $i, array('label' => '', 'value' => 1, 'class' => 'noborder')); // Add agent address select element $this->addElement('select', 'guarantor_address_' . $i, array('label' => 'Please select', 'required' => true, 'multiOptions' => array('' => 'Please select'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please select guarantor {$i}'s address", 'notEmptyInvalid' => "Please select guarantor {$i}'s address")))))); $this->getElement('guarantor_address_' . $i)->removeDecorator('label'); // Remove 'nnn not found in haystack' error $this->getElement('guarantor_address_' . $i)->setRegisterInArrayValidator(false); // Add in manual entry forms if guarantor address not present if (isset($formData['guarantor_postcode_' . $i]) && trim($formData['guarantor_postcode_' . $i]) != '') { Application_Core_FormUtils::getAddressByPostcode($this, $formData, trim($formData['guarantor_postcode_' . $i]), 'guarantor_address_' . $i, 'guarantor_housename_' . $i, 'guarantor_street_' . $i, 'guarantor_town_' . $i, 'guarantor_city_' . $i, "guarantor {$i}'s"); $this->getElement('guarantor_address_' . $i)->setRequired(false); } $this->addElement('text', 'guarantor_homeletrefno_' . $i, array('label' => "HomeLet reference number", 'required' => true, 'maxlength' => '10', 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please enter guarantor {$i}'s HomeLet reference number", 'notEmptyInvalid' => "Please enter guarantor {$i}'s HomeLet reference number"))), array('regex', true, array('pattern' => '/\\d{7}/', 'messages' => "Our reference number for guarantor {$i} must be at least seven digits long"))))); $this->addElement('text', 'guarantors_dob_' . $i, array('label' => "Date of Birth (DD/MM/YYYY)", 'required' => true, 'class' => "hasDatepicker", 'maxlength' => '10', 'filters' => array('StringTrim'), 'validators' => array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Please select guarantor {$i}'s date of birth", 'notEmptyInvalid' => "Please select guarantor {$i}'s date of birth"))), array('regex', true, array('pattern' => '/^\\d\\d\\/\\d\\d\\/\\d\\d\\d\\d$/', 'messages' => "Guarantor {$i}'s date of birth incomplete"))))); } // Hide errors Application_Core_FormUtils::removeFormErrors($this); }
/** * 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 (isset($formData['landlord_postcode']) && trim($formData['landlord_postcode']) != '') { Application_Core_FormUtils::getAddressByPostcode($this, $formData, trim($formData['landlord_postcode']), 'landlord_address', 'landlord_housename', 'landlord_street', 'landlord_town', 'landlord_city', 'landlord\'s'); } // Ensure that all of landlord1_name, landlord_company_name are mandatory if all empty, all non-mandatory otherwise if (isset($formData['landlord1_name']) && trim($formData['landlord1_name']) != '' || isset($formData['landlord_company_name']) && trim($formData['landlord_company_name']) != '') { // One or more of the fields have a value, make them all non-mandatory $this->getElement('landlord1_name')->setRequired(false); $this->getElement('landlord_company_name')->setRequired(false); } // Hide Errors Application_Core_FormUtils::removeFormErrors($this); // Call original isValid() return parent::isValid($formData); }