Beispiel #1
0
 /**
  * Configure form
  */
 public function init()
 {
     $this->setAttrib('class', 'ajaxForm formAjaxValidate');
     $registry = MyProject_Registry::getInstance();
     $currentLocale = $registry->registry('locale');
     //
     // Login Information fields
     //
     $this->addElement('info', 'info3', array('label' => __('Login Information'), 'messages' => array(__('Your username and password must both be at least 8 characters long and are case-sensitive. Please do not enter accented characters.'), __('We recommend that your password is not a word you can find in the dictionary, includes both capital and lower case letters, and contains at least one special character (1-9, !, *, _, etc.).'), __('Your password will be encrypted and stored in our system. Due to the encryption, we cannot retrieve your password for you. If you lose or forget your password, we offer the ability to reset it.'))));
     $this->addElement('radio', 'gender', array('helper' => 'formMultiRadio', 'label' => __('Gender:'), 'label_class' => 'compact', 'required' => true, 'multioptions' => array(1 => __('Male'), 2 => __('Female'))));
     $this->getElement('gender')->setAttrib('label_class', 'compact');
     // login
     $this->addElement('text', 'username', array('label' => __('Username:'******'required' => true, 'description' => __('May only contain letters, numbers, and underscore (_) and 8-20 characters long.')));
     $this->getElement('username')->addValidator('StringLength', true, array(8, 20))->addValidator('Regex', false, array('pattern' => '/^[0-9A-Za-z+\\_]*$/', 'messages' => array('regexNotMatch' => __('Invalide Username should only contain letters, numbers, and underscore (_).'))));
     // password
     $this->addElement('password', 'password', array('label' => __('Password:'******'required' => true, 'description' => __('Must be 6-25 characters long.')));
     $this->getElement('password')->addValidator('StringLength', true, array(6, 25));
     $this->addElement('password', 'password_check', array('label' => __('Please re-enter your password:'******'required' => true, 'description' => __('Must match the password you entered just above.')));
     $this->getElement('password_check')->addValidator('StringEquals', true, array('field1' => 'password', 'field2' => 'password_check', 'messages' => array('notMatch' => __("Passwords don't match, please enter them again"))));
     $this->addElement('checkbox', 'remember_me', array('label' => __('Remember Me'), 'description' => __("If you don't want to bother with having to login every time you visit the site, then checking \"Remember Me\" will place a unique identifier only our site can read that we'll use to identify you and log you in automatically each time you visit.")));
     $this->addElement('checkbox', 'therms', array('label' => __('I agree to the bellow terms'), 'required' => true, 'description' => sprintf(__('By checking this, you are indicating that you are agree with the %s Terms of Use %s.'), '<a href="#">', '</a>')));
     $thermsRequired = new Zend_Validate_InArray(array(1));
     $thermsRequired->setMessage('You should accept the Terms of Use');
     $this->getElement('therms')->addValidator($thermsRequired);
     $this->addDisplayGroup(array('info3', 'gender', 'username', 'password', 'password_check', 'remember_me', 'therms'), 'login_information');
     $this->getDisplayGroup('login_information')->setLegend(__('Login Information'));
     // submit and reset buttons
     $this->addElement('reset', 'reset', array('label' => __('Cancel')))->addElement('submit', 'update', array('label' => __('Submit')))->addDisplayGroup(array('reset', 'update'), 'buttons');
     // add class for buttons
     $this->getDisplayGroup('buttons')->setAttrib('class', 'fieldsetButtons');
 }
 /**
  * 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())
 {
     $pageSession = new Zend_Session_Namespace('tenants_insurance_quote');
     // If correspondence address is set to be the same as insured address, copy the address values across
     if (isset($formData['cor_same_address']) && $formData['cor_same_address'] == 'yes') {
         // NOTE: THIS BIT OF CODE MEANS BOTH ADDRESS SUBFORMS MUST APPEAR ON THE SAME PAGE
         $formData['cor_house_number_name'] = $formData['ins_house_number_name'];
         $formData['cor_postcode'] = $formData['ins_postcode'];
         $formData['cor_address'] = $formData['ins_address'];
         $findPostcode = $formData['ins_postcode'];
     }
     // If a postcode is present, look it up and populate the allowed values of the associated dropdown
     if (isset($formData['cor_postcode']) && trim($formData['cor_postcode']) != '') {
         $postcode = trim($formData['cor_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $cor_address = $this->getElement('cor_address');
         $cor_address->setMultiOptions($addressList);
         $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
         $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Correspondence address does not match with postcode'));
         $cor_address->addValidator($validator, true);
     }
     // If a value for an address lookup is present, the house name or number is not required
     if (isset($formData['cor_postcode'])) {
         $this->getElement('cor_house_number_name')->setRequired(false);
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
 public function init()
 {
     $seccion = new Application_Model_Seccion();
     $array = $seccion->listarSeccionesPeriodoActualActivos();
     $include = new Application_Model_Includes();
     //$q2a=$include->query2array($array, 'iSeccIdSeccion','vSeccDescripcion');
     $q2a = $include->querytoeach($array, "iSeccIdSeccion");
     $validator = new Zend_Validate_InArray($q2a);
     $validator->setHaystack($q2a);
     $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Eliga una sección'));
     $this->setAction('/admin/agregarcurso')->setMethod('post')->setAttrib('id', 'formLogin');
     // Crea un y configura el elemento username
     $nombrecurso = $this->createElement('text', 'nombrecurso', array('label' => 'Nombre del Curso', 'placeholder' => 'Máximo 150 caracteres'));
     $nombrecurso->addValidator('notEmpty', true, array('messages' => array('isEmpty' => 'Campo requerido')))->addValidator('regex', true, array('pattern' => '/^[(a-z A-Z)]+$/', 'messages' => array('regexNotMatch' => 'Sólo Letras')))->addValidator('stringLength', false, array(5, 150, 'messages' => "Entre 5 a 150 caracteres"))->setRequired(true)->addFilter('StringToUpper');
     $nombrecurso->setDecorators(array('ViewHelper', 'Description', 'Errors', array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')), array(array('td' => 'HtmlTag'), array('tag' => 'td')), array('Label', array('tag' => 'td'))));
     $descripcion = $this->createElement('text', 'descripcion', array('label' => 'Descripción', 'placeholder' => 'Breve descripción del curso'));
     $descripcion->addValidator('notEmpty', true, array('messages' => array('isEmpty' => 'Campo requerido')))->addValidator('regex', true, array('pattern' => '/^[(a-z A-Z 0-9)]+$/', 'messages' => array('regexNotMatch' => 'Sólo Letras')))->setRequired(true)->addFilter('StringToUpper');
     $descripcion->setDecorators(array('ViewHelper', 'Description', 'Errors', array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')), array(array('td' => 'HtmlTag'), array('tag' => 'td')), array('Label', array('tag' => 'td'))));
     $gradosactuales = new Application_Model_Grado();
     $includes = new Application_Model_Includes();
     $arraygrados = $gradosactuales->listarGradosActivos();
     $arraygradostoarray = $includes->query2array($arraygrados, 'iGradoIdGrado', 'vGradoDescripcion');
     $grado = $this->createElement('select', 'cbogrado', array('label' => 'Grado', 'autocomplete' => false, 'multiOptions' => $arraygradostoarray, 'onChange' => 'cargarseccion();'));
     $grado->setDecorators(array('ViewHelper', 'Description', 'Errors', array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')), array(array('td' => 'HtmlTag'), array('tag' => 'td')), array('Label', array('tag' => 'td'))));
     $seccion = $this->createElement('select', 'cboseccion', array('label' => 'Seccion', 'multiOptions' => array("0" => "Seleccionar Sección")));
     $seccion->addValidator($validator);
     $seccion->addValidator('notEmpty', true, array('messages' => array('isEmpty' => 'Campo requerido')));
     $seccion->setDecorators(array('ViewHelper', 'Description', 'Errors', array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')), array(array('td' => 'HtmlTag'), array('tag' => 'td')), array('Label', array('tag' => 'td'))));
     // Añade los elementos al formulario:
     $this->addElement($nombrecurso)->addElement($descripcion)->addElement($grado)->addElement($seccion)->addElement('submit', 'registrar', array('label' => 'Registrar'));
 }
 public function isValid($formData = array())
 {
     if (isset($formData['ins_property_postcode']) && trim($formData['ins_property_postcode']) != '') {
         $postcode = trim($formData['ins_property_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         if (isset($postcode) && preg_match('/^IM|^GY|^JE/i', $postcode)) {
             return;
         } else {
             foreach ($addresses as $address) {
                 $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
             }
         }
         $ins_address = $this->getElement('property_address');
         $ins_address->setMultiOptions($addressList);
         $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
         $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
         $ins_address->addValidator($validator, true);
     }
     // If a value for an address lookup is present, the house name or number is not required
     if (isset($formData['ins_property_postcode'])) {
         $this->getElement('property_number_name')->setRequired(false);
     }
     return parent::isValid($formData);
 }
Beispiel #5
0
 public function isValid($postData)
 {
     $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
     $customerReferenceNumber = $pageSession->CustomerRefNo;
     $propertyManager = new Manager_Insurance_Portfolio_Property();
     $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber);
     $propertyArray = $propertyObjects->toArray();
     $optionList = array('' => '--- please select ---');
     foreach ($propertyArray as $property) {
         $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode'];
     }
     // Get the subfoem element for property address that the bank may have interest in
     $propertyAddressSelect = $this->getElement('claim_property');
     $propertyAddressSelect->setMultiOptions($optionList);
     $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList)));
     $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Not in list'));
     $propertyAddressSelect->addValidator($validator, true);
     // Set the selected to 0
     $propertyAddressSelect->setValue('0');
     $claimTypeList = array('' => '--- please select ---');
     $claimTypesSelect = $this->getElement('claim_type');
     $claimTypes = new Datasource_Insurance_PreviousClaimTypes();
     $claimTypeObjects = $claimTypes->getPreviousClaimTypes(Model_Insurance_ProductNames::LANDLORDSPLUS);
     foreach ($claimTypeObjects as $ClaimType) {
         $claimTypeList[$ClaimType->getClaimTypeID()] = $ClaimType->getClaimTypeText();
     }
     $claimTypesSelect->setMultiOptions($claimTypeList);
     return parent::isValid($postData);
 }
Beispiel #6
0
 public function isValid($formData = array())
 {
     // If a postcode is present, look it up and populate the allowed values of the associated dropdown
     if (isset($formData['postcode']) && trim($formData['postcode']) != '') {
         $postcode = trim($formData['postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $address = $this->getElement('address');
         $address->setMultiOptions($addressList);
         $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
         $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Address does not match with postcode'));
         $address->addValidator($validator, true);
     }
     // If a value for an address lookup is present, the house name or number is not required
     if (isset($formData['address_postcode']) && $formData['address_postcode'] != '') {
         $this->getElement('postcode')->setRequired(false);
         $this->getElement('address')->setRequired(false);
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
Beispiel #7
0
 /**
  * @param  string  $format
  * @return boolean
  */
 private function validateFormat($format)
 {
     $formatValidator = new \Zend_Validate_InArray($this->acceptedFormats);
     $formatValidator->setMessage("'%value%' ist kein unterstuetztes Format", \Zend_Validate_InArray::NOT_IN_ARRAY);
     if (!$formatValidator->isValid($format)) {
         $messages = array_values($formatValidator->getMessages());
         $this->addError(new Error('format', $format, $messages));
         return false;
     }
     return true;
 }
 public function isValid($value)
 {
     $ret = parent::isValid($value);
     if ($ret) {
         $mapper = new Application_Model_CsrfhashMapper();
         $mapper->deleteByCsrf($value);
     }
     return $ret;
 }
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $validator = new Zend_Validate_InArray(array(1, 'a', 2.3));
     $this->assertTrue($validator->isValid(1));
     $this->assertTrue($validator->isValid(1.0));
     $this->assertTrue($validator->isValid('1'));
     $this->assertTrue($validator->isValid('a'));
     $this->assertFalse($validator->isValid('A'));
     $this->assertTrue($validator->isValid(2.3));
     $this->assertTrue($validator->isValid(2.3));
 }
Beispiel #10
0
 public function isValidImage($file, $max, $height, $width, $allowedTypes)
 {
     //check if its a proper image
     if ($file) {
         if (!$file['size']) {
             return array('Error' => 'Image: The file does not appear to be a proper image');
         }
     }
     //check size
     $validator = new Zend_Validate_Between('1', $max);
     if ($validator->isValid($file['size'])) {
     } else {
         // value failed validation; print reasons
         foreach ($validator->getMessages() as $message) {
             return array('Error' => 'Image:' . $message);
         }
     }
     //this validator uses GD
     if ($fileSizes = getimagesize($file['tmp_name'])) {
         $mime = $fileSizes['mime'];
         $actualWidth = $fileSizes[0];
         $actualHeight = $fileSizes[1];
         //check sizes
         if ($actualHeight > $height) {
             return array('Error' => 'Image height is bigger than ' . $height . ' pixels');
         }
         if ($actualWidth > $width) {
             return array('Error' => 'Image width is bigger than ' . $width . ' pixels');
         }
         //check type
         $validator = new Zend_Validate_InArray($allowedTypes);
         if ($valid = $validator->isValid($mime)) {
             if ($valid != '1') {
                 foreach ($validator->getMessages() as $message) {
                     return array('Error' => 'Image:' . $message);
                 }
             }
         }
     } else {
         return array('Error' => 'Image: Wrong file type');
     }
     return true;
 }
Beispiel #11
0
 /**
  * validiert den paramter tpye
  *
  * @param string $type
  * @return boolean
  */
 private function validateType($type)
 {
     $typeValidator = new \Zend_Validate_InArray(array('page', 'template', 'website'));
     if (!$typeValidator->isValid($type)) {
         $messages = array_values($typeValidator->getMessages());
         $this->addError(new Error('type', $type, $messages));
         return false;
     }
     return true;
 }
 public function isValid($postData)
 {
     $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
     $customerReferenceNumber = $pageSession->CustomerRefNo;
     $propertyManager = new Manager_Insurance_Portfolio_Property();
     $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber);
     $propertyArray = $propertyObjects->toArray();
     $optionList = array('' => '--- please select ---');
     foreach ($propertyArray as $property) {
         $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode'];
     }
     // Get the subfoem element for property address that the bank may have interest in
     $propertyAddressSelect = $this->getElement('bank_property');
     $propertyAddressSelect->setMultiOptions($optionList);
     $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList)));
     $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Property not in list'));
     $propertyAddressSelect->addValidator($validator, true);
     return parent::isValid($postData);
 }
Beispiel #13
0
 /**
  * @param \Magento\Eav\Helper\Data $eavData
  */
 public function __construct(\Magento\Eav\Helper\Data $eavData)
 {
     $this->_eavData = $eavData;
     //set data haystack
     $haystack = $this->_eavData->getInputTypesValidatorData();
     //reset message template and set custom
     $this->_messageTemplates = null;
     $this->_initMessageTemplates();
     //parent construct with options
     parent::__construct(['haystack' => $haystack, 'strict' => true]);
 }
Beispiel #14
0
 /**
  * Construct
  */
 public function __construct()
 {
     //set data haystack
     /** @var $helper Mage_Eav_Helper_Data */
     $helper = Mage::helper('eav');
     $haystack = $helper->getInputTypesValidatorData();
     //reset message template and set custom
     $this->_messageTemplates = null;
     $this->_initMessageTemplates();
     //parent construct with options
     parent::__construct(array('haystack' => $haystack, 'strict' => true));
 }
 /**
  * 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())
 {
     $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
     // If a postcode is present, look it up and populate the allowed values of the associated dropdown
     if (isset($formData['cor_postcode']) && trim($formData['cor_postcode']) != '') {
         $postcode = trim($formData['cor_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $cor_address = $this->getElement('cor_address');
         $cor_address->setMultiOptions($addressList);
         $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
         $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Correspondence address does not match with postcode'));
         $cor_address->addValidator($validator, true);
     }
     // If a value for an address lookup is present, the house name or number
     // is not required
     if (isset($formData['cor_postcode'])) {
         $this->getElement('cor_house_number_name')->setRequired(false);
     }
     // todo: sort out server-side validation for foreign address stuff
     // If the address is overseas, toggle  the required status for the
     // relevant fields.
     if (isset($formData['cor_foreign_address']) && 1 == $formData['cor_foreign_address']) {
         $this->getElement('cor_address')->setRequired(false);
         $this->getElement('cor_address_postcode')->setRequired(false);
         $this->getElement('cor_address_line1')->setRequired(true);
         $this->getElement('cor_address_line2')->setRequired(true);
         $this->getElement('country')->setRequired(true);
         // Also change the validators for the postcode field
         $this->getElement('cor_postcode')->setValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Please enter zip/postal code for your correspondence address', 'notEmptyInvalid' => 'Please enter a valid zip/postal code for your correspondence address')))));
         $this->getElement('cor_address_postcode')->setValidators(array());
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
Beispiel #16
0
 /**
  * Checks if the provided value represents a boolean.
  *
  * @param mixed $value
  * @return boolean True if $value represents a boolean, false otherwise.
  */
 public function isValid($value)
 {
     if (is_array($value)) {
         // Arrays are not accepted.
         // Ensure that the value is not passed to the parent
         // isValid() method as it raises an error when generating
         // the failure message if PHP 5.4 is used.
         // See #14 for details:
         // https://github.com/Matthimatiker/MolComponents/issues/14
         return false;
     }
     return parent::isValid($value);
 }
 public function init()
 {
     parent::init();
     $options = Opus_EnrichmentKey::getAll();
     $values = array();
     $translator = $this->getTranslator();
     $this->setDisableTranslator(true);
     // keys are translated below if possible
     foreach ($options as $index => $option) {
         $keyName = $option->getName();
         $values[] = $keyName;
         $translationKey = 'Enrichment' . $keyName;
         if (!is_null($translator) && $translator->isTranslated($translationKey)) {
             $this->addMultiOption($keyName, $translator->translate($translationKey));
         } else {
             $this->addMultiOption($keyName, $keyName);
         }
     }
     $validator = new Zend_Validate_InArray($values);
     $validator->setMessage('validation_error_unknown_enrichmentkey');
     $this->addValidator($validator);
 }
 /**
  * Overrides init() in Zend_Form
  * 
  * @access public
  * @return void
  */
 public function init()
 {
     // init the parent
     parent::init();
     // set the form's method
     $this->setMethod('post');
     $groupModel = new Group();
     $groupsOptions = $groupModel->findPairs();
     $uniqueUsernameValidator = new Zend_Validate_Db_NoRecordExists(array('table' => 'backoffice_users', 'field' => 'username'));
     $uniqueEmailValidator = new Zend_Validate_Db_NoRecordExists(array('table' => 'backoffice_users', 'field' => 'email'));
     $groupsInArrayValidator = new Zend_Validate_InArray(array_keys($groupsOptions));
     $groupsInArrayValidator->setMessage('Please select at least one group. If you are not sure about which group is better, select "member".');
     $username = new Zend_Form_Element_Text('username');
     $username->setOptions(array('label' => 'Username', 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty', $uniqueUsernameValidator)));
     $this->addElement($username);
     $email = new Zend_Form_Element_Text('email');
     $email->setOptions(array('label' => 'Email', 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty', $uniqueEmailValidator)));
     $this->addElement($email);
     $firstname = new Zend_Form_Element_Text('firstname');
     $firstname->setOptions(array('label' => 'First name', 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty')));
     $this->addElement($firstname);
     $lastname = new Zend_Form_Element_Text('lastname');
     $lastname->setOptions(array('label' => 'Last name', 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty')));
     $this->addElement($lastname);
     $phoneNumber = new Zend_Form_Element_Text('phone_number');
     $phoneNumber->setOptions(array('label' => 'Phone number', 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty')));
     $this->addElement($phoneNumber);
     $groups = new Zend_Form_Element_MultiCheckbox('groups');
     $groups->setOptions(array('label' => 'Select the one or more user groups for this user', 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty', $groupsInArrayValidator), 'multiOptions' => $groupsOptions));
     $this->addElement($groups);
     $id = new Zend_Form_Element_Hidden('id');
     $id->setOptions(array('validators' => array(new Zend_Validate_Regex('/^\\d*$/'))));
     $this->addElement($id);
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setOptions(array('label' => 'Save user', 'required' => true, 'order' => 100));
     $this->addElement($submit);
     $this->addDisplayGroup(array('username', 'email', 'firstname', 'lastname', 'phone_number'), 'userdata')->getDisplayGroup('userdata')->setLegend('User details');
     $this->addDisplayGroup(array('groups'), 'usergroups')->getDisplayGroup('usergroups')->setLegend('Groups');
 }
Beispiel #19
0
 /**
  * Configure form
  */
 public function init()
 {
     $this->setAttrib('class', 'formAjaxValidate');
     //
     // Personal Information fields
     //
     $this->addElement('info', 'info1', array('label' => __('Personal Information'), 'messages' => array(__('Please enter your name and address as they are listed for your debit card, credit card, or bank account.'))));
     $this->addElement('radio', 'gender', array('label' => __('Gender:'), 'required' => true, 'multioptions' => array(1 => __('Male'), 0 => __('Female'))));
     $this->getElement('gender')->setAttrib('label_class', 'compact');
     $this->addElement('text', 'first_name', array('label' => __('First Name:'), 'required' => true));
     $this->addElement('text', 'last_name', array('label' => __('Last Name:'), 'required' => true));
     // @todo
     $this->addElement('date', 'birthday', array('label' => __('Birthday:'), 'required' => true));
     $this->addElement('text', 'addr1', array('label' => __('Address:')));
     $this->addElement('text', 'addr2', array());
     $this->addElement('select', 'country_id', array('label' => __('Country:'), 'multioptions' => array()));
     $this->addElement('select', 'state_id', array('label' => __('State:'), 'multioptions' => array()));
     $this->addElement('text', 'zipcode', array('label' => __('Zip/Postal Code:')));
     $this->addElement('text', 'city', array('label' => __('City:')));
     $this->addElement('select', 'sexuality_id', array('helper' => 'FormFancySelect', 'label' => __('Sexuality:'), 'notice' => __('Choose from the list'), 'required' => true, 'multioptions' => array('1' => 'Hetero', '2' => 'Bi', '3' => 'Gay')));
     $this->addElement('multiselect', 'lookingfor_id', array('helper' => 'FormFancySelect', 'label' => __('Her for:'), 'multiple' => true, 'show_choice' => true, 'notice' => __('Choose from the list'), 'required' => true, 'multioptions' => array('1' => 'Chatting', '2' => 'Promote Myself', '3' => 'Meeting new people', '4' => 'Flirting', '5' => 'Find the true love')));
     $this->addDisplayGroup(array('info1', 'gender', 'first_name', 'last_name', 'birthday', 'addr1', 'addr2', 'country_id', 'state_id', 'zipcode', 'city', 'sexuality_id', 'lookingfor_id'), 'personal_information');
     $this->getDisplayGroup('personal_information')->setLegend(__('Personal Information'));
     //
     // Contact Information fields
     //
     $this->addElement('info', 'info2', array('label' => __('Contact Information'), 'messages' => array(__('Please enter your full email address, for example, name@domain.com'), __('It is important that you provide a valid, working email address that you have access to as it must be verified before you can use your account.'), __('Please enter a land line number, not a mobile phone number.'), str_replace(array('[link]', '[/link]'), array('<a href="#todo">', '</a>'), __('Your phone number will not be shared or used for telemarketing. Your information is protected by our [link]Privacy Policy[/link].')))));
     $this->addElement('radio', 'how_contact', array('helper' => 'formMultiRadio', 'label' => __('How to Contact You ?'), 'required' => true, 'multioptions' => array(1 => __('Phone'), 0 => __('Email'))));
     $this->getElement('how_contact')->setAttrib('label_class', 'compact');
     $this->addElement('text', 'email', array('label' => __('Email:'), 'required' => true, 'description' => __('We will never sell or disclose your email address to anyone. Once your account is setup, you may add additional email addresses.')));
     $this->getElement('email')->addValidator('EmailAddress', true, array('messages' => array('emailAddressInvalid' => __('This does not appear to be a valid email address'), 'emailAddressInvalidHostname' => __('This does not appear to be a valid email address'), 'emailAddressInvalidMxRecord' => __('This does not appear to be a valid email address'), 'emailAddressDotAtom' => __('This does not appear to be a valid email address'), 'emailAddressQuotedString' => __('This does not appear to be a valid email address'), 'emailAddressInvalidLocalPart' => __('This does not appear to be a valid email address'))));
     $this->addElement('text', 'email_check', array('label' => __('Re-enter Email:'), 'required' => true, 'description' => __('Must match the email address you just entered above.')));
     $this->getElement('email_check')->addValidator('StringEquals', true, array('field1' => 'email', 'field2' => 'email_check', 'messages' => array('notMatch' => __("Emails don't match, please enter them again"))));
     $this->addElement('text', 'phone', array('label' => __('Phone:')));
     $this->addElement('text', 'fax', array('label' => __('Fax:')));
     $this->addElement('radio', 'subject', array('helper' => 'formMultiRadio', 'label' => __('Message Subject:  '), 'multioptions' => array(1 => __('Help, my brother/sister is driving me crazy!'), 1 => __("How can I tell my father/mother, it's time for them to retire?"), 2 => __("I'm exasperated with an awkward partner!"), 3 => __("How do I stop my family members from interfering?"), 4 => __("Other:")), 'container_class' => 'wide'));
     $this->addElement('textarea', 'message', array('label' => __('Your Message:'), 'required' => true, 'description' => __('Must be 250 characters or less.')));
     $this->addElement('textarea', 'message_wide', array('label' => __('Your Message:'), 'required' => true, 'description' => __("We'd love to get your feedback on any of the products or services we offer or on your experience with us."), 'container_class' => 'wide'));
     $this->addElement('text', 'keywords', array('label' => __('Keywords:'), 'required' => true, 'container_class' => 'wide'));
     $this->addElement('multiselect', 'current_availability_id', array('label' => __('What is your current availability?'), 'required' => true, 'description' => __('Use the CTRL key to select more than one.'), 'multioptions' => array(1 => __('Part-time'), 2 => __('Full-time (Days)'), 3 => __('Full-time (Swing)'), 4 => __('Full-time (Graveyard)'), 5 => __('Weekends Only'))));
     $this->addElement('multiCheckbox', 'availability_id', array('label' => __('What is your current availability?'), 'required' => true, 'multioptions' => array(1 => __('Part-time'), 2 => __('Full-time (Days)'), 3 => __('Full-time (Swing)'), 4 => __('Full-time (Graveyard)'), 5 => __('Weekends Only'))));
     $this->addDisplayGroup(array('info2', 'how_contact', 'email', 'email_check', 'phone', 'fax', 'subject', 'message', 'message_wide', 'keywords', 'current_availability_id', 'availability_id'), 'contact_information');
     $this->getDisplayGroup('contact_information')->setLegend(__('Contact Information'));
     //
     // Login Information fields
     //
     $this->addElement('info', 'info3', array('label' => __('Login Information'), 'messages' => array(__('Your username and password must both be at least 8 characters long and are case-sensitive. Please do not enter accented characters.'), __('We recommend that your password is not a word you can find in the dictionary, includes both capital and lower case letters, and contains at least one special character (1-9, !, *, _, etc.).'), __('Your password will be encrypted and stored in our system. Due to the encryption, we cannot retrieve your password for you. If you lose or forget your password, we offer the ability to reset it.'))));
     $this->addElement('text', 'username', array('label' => __('Username:'******'required' => true, 'description' => __('May only contain letters, numbers, and underscore (_) and 8-20 characters long.')));
     $this->addElement('password', 'password', array('label' => __('Password:'******'required' => true, 'description' => __('Must be 6-25 characters long.')));
     $this->addElement('password', 'password_check', array('label' => __('Please re-enter your password:'******'required' => true, 'description' => __('Must match the password you entered just above.')));
     $this->getElement('password_check')->addValidator('StringEquals', true, array('field1' => 'password', 'field2' => 'password_check', 'messages' => array('notMatch' => __("Passwords don't match, please enter them again"))));
     $this->addElement('checkbox', 'remember_me', array('label' => __('Remember Me'), 'description' => __("If you don't want to bother with having to login every time you visit the site, then checking \"Remember Me\" will place a unique identifier only our site can read that we'll use to identify you and log you in automatically each time you visit.")));
     $this->addElement('checkbox', 'therms', array('label' => __('I agree to the bellow terms'), 'required' => true, 'description' => sprintf(__('By checking this, you are indicating that you are agree with the %sTerms of Use%s.'), '<a href="#">', '</a>')));
     $thermsRequired = new Zend_Validate_InArray(array(1));
     $thermsRequired->setMessage('You should accept the Terms of Use');
     $this->getElement('therms')->addValidator($thermsRequired);
     $this->addDisplayGroup(array('info3', 'username', 'password', 'password_check', 'remember_me', 'therms'), 'login_information');
     $this->getDisplayGroup('login_information')->setLegend(__('Login Information'));
     //
     // Avatar
     //
     $this->addElement('info', 'info5', array('label' => __('Avatar Information'), 'messages' => array(__('You can upload a JPG, GIF or PNG file.'), __('File size limit 4 MB. If your upload does not work, try a smaller picture.'))));
     // add synchron upload support
     $this->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);
     $this->addElement('file', 'avatar_file', array('label' => __('Upload your Avatar:'), 'required' => true, 'container_class' => 'wide'));
     $this->addElement('checkbox', 'therms_file', array('label' => __('I certify that I have the right to distribute this picture and that it does not violate the Terms of Use'), 'required' => true, 'container_class' => 'wide'));
     $thermsRequired = new Zend_Validate_InArray(array(1));
     $thermsRequired->setMessage('You should accept the Terms of Use');
     $this->getElement('therms_file')->addValidator($thermsRequired);
     $this->addDisplayGroup(array('info5', 'avatar_file', 'therms_file'), 'avatar');
     $this->getDisplayGroup('avatar')->setLegend(__('Avatar'));
     //
     // Verification fields
     //
     $this->addElement('info', 'info4', array('label' => __('Verification Information'), 'messages' => array(__('Type the characters you see in this picture. This ensures that a person, not an automated program, is creating this account.'))));
     // init ReCaptcha service
     $pubKey = '6Lf59QQAAAAAANrLNTVbBEt4I1TgAIwuQuc22iuN';
     $privKey = '6Lf59QQAAAAAAFaT3xLxeoIHkPNx3OFeTBcv1bXS';
     $recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);
     // inir ReCaptcha adapter
     $adapter = new Zend_Captcha_ReCaptcha();
     $adapter->setService($recaptcha);
     // build element
     $this->addElement('captcha', 'captcha', array('captcha' => $adapter));
     $this->addDisplayGroup(array('info4', 'captcha'), 'check_information');
     $this->getDisplayGroup('check_information')->setLegend(__('Verification'));
     // submit and reset buttons
     $this->addElement('reset', 'reset', array('label' => __('Cancel')))->addElement('submit', 'update', array('label' => __('Submit')))->addDisplayGroup(array('reset', 'update'), 'buttons');
     // add class for buttons
     $this->getDisplayGroup('buttons')->setAttrib('class', 'fieldsetButtons');
 }
 /**
  * Ensures that getStrict() returns expected default value
  *
  * @return void
  */
 public function testGetStrict()
 {
     $validator = new Zend_Validate_InArray(array(1, 2, 3));
     $this->assertEquals(false, $validator->getStrict());
 }
Beispiel #21
0
 public function testRecursiveStandalone()
 {
     $validator = new Zend_Validate_InArray(array('firstDimension' => array('test', 0, 'A'), 'secondDimension' => array('value', 2, 'a')));
     $this->assertFalse($validator->isValid('A'));
     $validator->setRecursive(true);
     $this->assertTrue($validator->isValid('A'));
 }
Beispiel #22
0
 /**
  * Validate element value
  *
  * @param  array   $data
  * @param  mixed   $context
  * @return boolean
  */
 public function isValid($data, $context = null, $removeNotPresentFields = false)
 {
     $this->setHaystack($this->getList());
     return parent::isValid($data, $context, $removeNotPresentFields);
 }
Beispiel #23
0
 /**
  * @param integer $allowedType
  * @return boolean
  */
 private function validateAllowedType($allowedType, $field)
 {
     $typeValidator = new \Zend_Validate_InArray($this->expectedAllowedTypes);
     $typeValidator->setMessage("'%value%' ist kein unterstuetzter Import-Typ'", \Zend_Validate_InArray::NOT_IN_ARRAY);
     if (!$typeValidator->isValid($allowedType)) {
         $messages = array_values($typeValidator->getMessages());
         $this->addError(new Error($field, $allowedType, $messages));
         return false;
     }
     return true;
 }
 /**
  * returns an validator for settings params or error array
  *
  * @return Zend_Filter_Input|array on success data on error message array
  * @param array $data current data for validation
  */
 public function validate($data)
 {
     // define filter
     $filterTrim = new Zend_Filter_StringTrim();
     $filter = array('deleteItems' => $filterTrim, 'imagesPosition' => $filterTrim, 'imagesHeight' => $filterTrim, 'language' => $filterTrim, 'refresh' => $filterTrim, 'lastrefresh' => $filterTrim, 'view' => $filterTrim, 'offset' => $filterTrim, 'itemsperpage' => $filterTrim, 'selected' => $filterTrim, 'dateFilter' => $filterTrim, 'dateStart' => $filterTrim, 'dateEnd' => $filterTrim, 'search' => $filterTrim, 'unread' => $filterTrim, 'starred' => $filterTrim, 'currentPriorityStart' => $filterTrim, 'currentPriorityEnd' => $filterTrim, 'saveOpenCategories' => $filterTrim, 'openCategories' => $filterTrim, 'firstUnread' => $filterTrim, 'newWindow' => $filterTrim, 'public' => $filterTrim, 'anonymizer' => $filterTrim, 'sort' => $filterTrim, 'openitems' => $filterTrim, 'iconcache' => $filterTrim);
     // define validators
     $validatorType = new Zend_Validate_InArray(array("both", "multimedia", "messages"));
     $validatorType->setMessage(Zend_Registry::get('language')->translate('Only both, multimedia, message allowed'), Zend_Validate_InArray::NOT_IN_ARRAY);
     $validatorNotEmpty = new Zend_Validate_NotEmpty();
     $validatorNotEmpty->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_NotEmpty::IS_EMPTY);
     $validatorNum = new Zend_Validate_Int(Zend_Registry::get('session')->language);
     $validatorNum->setLocale(Zend_Registry::get('session')->language);
     $validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Int::NOT_INT);
     $validatorInArray = new Zend_Validate_InArray(array("top", "bottom"));
     $validatorInArray->setMessage(Zend_Registry::get('language')->translate('Only top or bottom allowed'), Zend_Validate_InArray::NOT_IN_ARRAY);
     $validatorLanguage = new Zend_Validate_InArray(Zend_Registry::get('language')->getList());
     $validatorLanguage->setMessage(Zend_Registry::get('language')->translate('Language is not available'), Zend_Validate_InArray::NOT_IN_ARRAY);
     $validatorDate = new Zend_Validate_Date();
     $validatorDate->setMessage(Zend_Registry::get('language')->translate('No valid date given'), Zend_Validate_Date::INVALID);
     $validatorDate->setMessage(Zend_Registry::get('language')->translate('No valid date given'), Zend_Validate_Date::FALSEFORMAT);
     $validatorBiggerThanZero = new Zend_Validate_GreaterThan(0);
     $validatorBiggerThanZero->setMessage(Zend_Registry::get('language')->translate('Value must be bigger than 0'), Zend_Validate_GreaterThan::NOT_GREATER);
     $validatorBetweenDays = new Zend_Validate_Between(0, 2000);
     $validatorBetweenDays->setMessage(Zend_Registry::get('language')->translate('Please choose a value between 0 and 2000 days'), Zend_Validate_Between::NOT_BETWEEN);
     $validatorBetweenItemsperpage = new Zend_Validate_Between(0, 200);
     $validatorBetweenItemsperpage->setMessage(Zend_Registry::get('language')->translate('Please choose a value between 0 and 200 items per page'), Zend_Validate_Between::NOT_BETWEEN);
     $validatorSort = new Zend_Validate_InArray(array("date", "dateasc", "priority", "priorityasc"));
     $validatorSort->setMessage(Zend_Registry::get('language')->translate('Only date or rating allowed'), Zend_Validate_InArray::NOT_IN_ARRAY);
     $validators = array('deleteItems' => array($validatorNum, $validatorBetweenDays, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'imagesPosition' => array($validatorInArray, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'language' => array($validatorLanguage, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'refresh' => array($validatorNum, $validatorBiggerThanZero, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'lastrefresh' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'view' => array($validatorType, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'offset' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'itemsperpage' => array($validatorNum, $validatorBetweenItemsperpage, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'selected' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'dateFilter' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'search' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'unread' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'starred' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'currentPriorityStart' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'currentPriorityEnd' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'saveOpenCategories' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'openCategories' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'firstUnread' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'newWindow' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'public' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'anonymizer' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'sort' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL, $validatorSort), 'openitems' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'iconcache' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL));
     // optional check date
     if (isset($data['dateFilter']) && $data['dateFilter'] == 1) {
         $validators['dateStart'] = $validatorDate;
         $validators['dateEnd'] = $validatorDate;
     } else {
         $validators['dateStart'] = array(Zend_Filter_Input::ALLOW_EMPTY => true);
         $validators['dateEnd'] = array(Zend_Filter_Input::ALLOW_EMPTY => true);
         $data['dateStart'] = '';
         $data['dateEnd'] = '';
     }
     // create validation main object
     $validator = new Zend_Filter_Input($filter, $validators, $data, array(Zend_Filter_Input::NOT_EMPTY_MESSAGE => Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Filter_Input::BREAK_CHAIN => false));
     // return filter input object
     return parent::validate($validator);
 }
 protected function _validateLteState($state)
 {
     $validator = new \Zend_Validate_InArray(array('true', 'false', '1', '0'));
     if (!$validator->isValid($state)) {
         AbstractService::throwValidateException($validator->getMessages(), ValidationCodes::INVALID_VALUE, 'lte');
     }
 }
Beispiel #26
0
 protected function validateBoolean($value, $name)
 {
     $booleanValidator = new \Zend_Validate_InArray(array('1', '0'));
     if (!$booleanValidator->isValid($value)) {
         $messages = array_values($booleanValidator->getMessages());
         $this->addError(new Error($name, $value, $messages));
         return false;
     }
     return true;
 }
Beispiel #27
0
 public function isValid($formData = array())
 {
     if (isset($formData['property_postcode']) && trim($formData['property_postcode']) != '') {
         $postcode = trim($formData['property_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $ins_address = $this->getElement('property_address');
         $ins_address->setMultiOptions($addressList);
         $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
         $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
         $ins_address->addValidator($validator, true);
     }
     // If a value for an address lookup is present, the house name or number is not required
     if (isset($formData['property_postcode'])) {
         $this->getElement('property_number_name')->setRequired(false);
     }
     // If a landline phone number is given, mobile is not mandatory
     if (isset($formData['phone_number']) && trim($formData['phone_number']) != '') {
         $this->getElement('mobile_number')->setRequired(false);
     }
     // If a mobile phone number is given, landline is not mandatory
     if (isset($formData['mobile_number']) && trim($formData['mobile_number']) != '') {
         $this->getElement('phone_number')->setRequired(false);
     }
     $result = parent::isValid($formData);
     $customerManager = new Manager_Core_Customer();
     $customer = $customerManager->getCustomerByEmailAddress($formData['email']);
     if ($customer) {
         // Customer exists, error the form
         $this->email->addError('This email is already in use. Have you signed up before?')->markAsError();
         return false;
     } else {
         return $result;
     }
 }
 /**
  * @group GH-365
  */
 public function testErrorMessageWithArrayValue()
 {
     $input = array(array('x'), array('y'));
     $validator = new Zend_Validate_InArray(array('a'));
     $validator->isValid($input);
     $messages = $validator->getMessages();
     $this->assertEquals("'x, y' was not found in the haystack", current($messages));
 }
 /**
  * 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())
 {
     $coverCount = 0;
     if (isset($formData['buildings_accidental_damage']) && $formData['buildings_accidental_damage'] == 1) {
         $coverCount++;
         $this->getElement('buildings_cover')->setRequired(true);
     }
     if (isset($formData['buildings_nil_excess']) && $formData['buildings_nil_excess'] == 1) {
         $coverCount++;
         $this->getElement('buildings_cover')->setRequired(true);
     }
     if (isset($formData['contents_accidental_damage']) && $formData['contents_accidental_damage'] == 1) {
         $coverCount++;
         $this->getElement('contents_cover')->setRequired(true);
     }
     if (isset($formData['contents_nil_excess']) && $formData['contents_nil_excess'] == 1) {
         $coverCount++;
         $this->getElement('contents_cover')->setRequired(true);
     }
     if (isset($formData['limited_contents']) && $formData['contents_cover'] > 0) {
         $coverCount++;
         $limitedContents = $this->getElement('limited_contents');
         $limitedContentsValidator = new Zend_Validate_LessThan(array('max' => 1));
         $limitedContentsValidator->setMessage('&nbsp;Limited Contents cannot be selected with Full Contents', Zend_Validate_LessThan::NOT_LESS);
         $limitedContents->addValidator($limitedContentsValidator, true);
     }
     if (isset($formData['limited_contents']) && $formData['limited_contents'] == 1 || (isset($formData['contents_cover']) && $formData['contents_cover'] > 0 || isset($formData['buildings_cover']) && $formData['buildings_cover'] > 0)) {
         $coverCount++;
     }
     // Set up validation for Building cover maximun
     // value can be empty OR Greater Than 50k and refer after 1000k
     $buildingsCover = $this->getElement('buildings_cover');
     $buildingsValidator = new Zend_Validate_GreaterThan(array('min' => 49999));
     $buildingsValidator->setMessage('Buildings cover must be over £50000', Zend_Validate_GreaterThan::NOT_GREATER);
     $buildingsCover->addValidator($buildingsValidator, true);
     // Set up validation for contents cover maximun
     // value can be empty OR Greater Than 10k and refer after 60k
     $contentsCover = $this->getElement('contents_cover');
     $contentsValidator = new Zend_Validate_GreaterThan(array('min' => 9999));
     $contentsValidator->setMessage('Contents cover must be over £10000', Zend_Validate_GreaterThan::NOT_GREATER);
     $contentsCover->addValidator($contentsValidator, true);
     $formData['covercount'] = $coverCount;
     $covers = $this->getElement('covercount');
     $optionsValidator = new Zend_Validate_GreaterThan(array('min' => 0));
     $optionsValidator->setMessage("You have not selected a cover", Zend_Validate_GreaterThan::NOT_GREATER);
     $covers->addValidator($optionsValidator, true);
     // If a postcode is or was present, look it up and populate the allowed values of the associated dropdown
     if (isset($formData['ins_postcode']) && trim($formData['ins_postcode']) != '') {
         $postcode = trim($formData['ins_postcode']);
         $postcodeLookup = new Manager_Core_Postcode();
         $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $postcode));
         $addressList = array('' => '--- please select ---');
         foreach ($addresses as $address) {
             $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
         }
         $ins_address = $this->getElement('ins_address');
         $ins_address->setMultiOptions($addressList);
         $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
         $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
         $ins_address->addValidator($validator, true);
     }
     if (isset($formData['ins_address_postcode']) && $formData['ins_address_postcode'] != '') {
         $this->getElement('ins_postcode')->setRequired(false);
         $this->getElement('ins_address')->setRequired(false);
     }
     // Call original isValid()
     return parent::isValid($formData);
 }
 /**
  * Private function to handle form population
  */
 private function _formStepCommonPopulate($pageForm, $stepNum)
 {
     $pageSession = new Zend_Session_Namespace('portfolio_insurance_quote');
     // First of all check that this form should be viewable and the user isn't trying to skip ahead
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     $tooFarAhead = false;
     if ((!isset($pageSession->completed) || is_null($pageSession->completed)) && $stepNum != 1) {
         $tooFarAhead = true;
         $lastCompleted = 1;
     } elseif ($stepNum > 1) {
         // Check to see if any pages previous to the one the user's trying to get to are incomplete
         $tooFarAhead = false;
         for ($i = 1; $i < $stepNum; $i++) {
             if (!isset($pageSession->completed[$i]) || !$pageSession->completed[$i]) {
                 $tooFarAhead = true;
                 $lastCompleted = $i;
                 break;
             }
         }
     }
     if ($tooFarAhead) {
         // Drop user onto page that needs completing
         $this->_helper->redirector->gotoUrl('/portfolio/insurance-quote/step' . $lastCompleted);
         return false;
     }
     // Echo out some debug info if not in production mode
     #Application_Core_Logger::log("Policy Number : " . $this->_policyNumber);
     #Application_Core_Logger::log("Customer Ref No : " . $this->_customerReferenceNumber);
     #Application_Core_Logger::log("Referrer : " . $this->_referrer);
     // Only populate from DB if we are in session and have a reference number
     if (isset($pageSession->CustomerRefNo)) {
         $customerReferenceNumber = $pageSession->CustomerRefNo;
         $policyNumber = $pageSession->PolicyNumber;
         $formData = array();
         // Populate $formData with data from model, if available
         switch ($stepNum) {
             case 1:
                 // Personal Details section
                 $customerManager = new Manager_Insurance_Portfolio_LegacyCustomer();
                 $customer = $customerManager->fetchByRefNo($customerReferenceNumber);
                 $formData['title'] = $customer['title'];
                 $formData['first_name'] = $customer['first_name'];
                 $formData['last_name'] = $customer['last_name'];
                 $formData['phone_number'] = $customer['telephone1'];
                 $formData['mobile_number'] = $customer['telephone2'];
                 $formData['email_address'] = $customer['email_address'];
                 $formData['date_of_birth_at'] = Application_Core_Utilities::mysqlDateToUk($customer['date_of_birth_at']);
                 // Get correspondance Address data
                 // Look up address again to populate dropdown
                 $formData['cor_house_number_name'] = $customer['address1'];
                 // Populate the correspondence address details
                 $formData['cor_address_line1'] = $customer['address1'];
                 $formData['cor_address_line2'] = $customer['address2'];
                 $formData['cor_address_line3'] = $customer['address3'];
                 $formData['cor_address_postcode'] = $customer['postcode'];
                 $formData['cor_postcode'] = $customer['postcode'];
                 $postcodeLookup = new Manager_Core_Postcode();
                 $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['cor_postcode']), $customer['address1']);
                 $addressList = array('' => '--- please select ---');
                 $filterString = is_numeric($formData['cor_house_number_name']) ? $formData['cor_house_number_name'] . ", " : $formData['cor_house_number_name'];
                 foreach ($addresses as $address) {
                     $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
                     if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) {
                         $addressID = $address['id'];
                     }
                 }
                 // Add some validation
                 $cor_address = $pageForm->getSubForm('subform_correspondenceaddress')->getElement('cor_address');
                 $cor_address->setMultiOptions($addressList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
                 $cor_address->addValidator($validator, true);
                 // Set the address to selected
                 $cor_address->setValue($addressID);
                 // Data Protection section
                 //Extract the DPA values from the session.
                 $dpaManager = new Manager_Core_DataProtection(Manager_Core_DataProtection::USE_SESSION);
                 $dpaItemArray = $dpaManager->getItems(null, Model_Core_DataProtection_ItemEntityTypes::INSURANCE);
                 #Zend_Debug::dump($dpaItemArray);die();
                 foreach ($dpaItemArray as $currentItem) {
                     switch ($currentItem->constraintTypeId) {
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_PHONEANDPOST:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_phone_post'] = 0;
                             } else {
                                 $formData['dpa_phone_post'] = 1;
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_SMSANDEMAIL:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_sms_email'] = 1;
                             } else {
                                 $formData['dpa_sms_email'] = 0;
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_resale'] = 1;
                             } else {
                                 $formData['dpa_resale'] = 0;
                             }
                             break;
                     }
                 }
                 // Initial Disclosure Agreement section
                 // As we have a customer reference number they must have saved step 1 at some point which means
                 // they must have agreed to the IDD section
                 $formData['idd'] = 1;
                 $pageForm->populate($formData);
                 break;
             case 2:
                 // Step needs to retrieve any properties that may have been added to this portfolio quote
                 // This data is NOT form data, just display data since the ajax has added the properties to the
                 // portfolio_properties table
                 $propertyArray = array();
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyArray = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $propNumb = count($propertyArray->toArray());
                 $formData['propNumb'] = count($propertyArray->toArray());
                 $this->view->propertyList = $propertyArray;
                 $this->view->stepNum = 2;
                 $pageForm->populate($formData);
                 break;
             case 3:
                 /*
                   This step display the properties and displays the quote value
                 */
                 $propertyArray = array();
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyArray = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $this->view->propertyList = $propertyArray;
                 $this->view->stepNum = 3;
                 break;
             case 4:
                 break;
                 /*
                     populates the remove property dialog
                 */
             /*
                 populates the remove property dialog
             */
             case "removePropertyDialog":
                 $request = $this->getRequest();
                 $formData['propertyid'] = $request->getParam('id');
                 $pageForm->populate($formData);
                 break;
             case "editInsuredAddress":
                 $request = $this->getRequest();
                 $formData['propertyid'] = $request->getParam('id');
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyObj = $propertyManager->getPropertyById($formData['propertyid']);
                 $formData['ins_house_number_name'] = $propertyObj->houseNumber;
                 $formData['ins_postcode'] = $propertyObj->postcode;
                 // Look up address again to populate dropdown
                 $postcodeLookup = new Manager_Core_Postcode();
                 $addresses = $postcodeLookup->getPropertiesByPostcode(preg_replace('/[^\\w\\ ]/', '', $formData['ins_postcode']));
                 $addressList = array('' => '--- please select ---');
                 $filterString = is_numeric($formData['ins_house_number_name']) ? $formData['ins_house_number_name'] . ", " : $formData['ins_house_number_name'];
                 foreach ($addresses as $address) {
                     $addressList[$address['id']] = $address['singleLineWithoutPostcode'];
                     if (stripos($address['singleLineWithoutPostcode'], $filterString) === 0) {
                         $addressID = $address['id'];
                     }
                 }
                 // Add some validation
                 $ins_address = $pageForm->getElement('ins_address');
                 $ins_address->setMultiOptions($addressList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($addressList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Insured address does not match with postcode'));
                 $ins_address->addValidator($validator, true);
                 // Set the address to selected
                 $ins_address->setValue($addressID);
                 //Zend_Debug::dump($propertyObj);die();
                 // Get Insured Address data
                 // Look up address again to populate dropdown
                 // Populate the correspondence address details
                 $formData['ins_address_line1'] = $propertyObj->address1;
                 $formData['ins_address_line2'] = $propertyObj->address2;
                 $formData['ins_address_line3'] = $propertyObj->address3;
                 $formData['ins_address_postcode'] = $propertyObj->postcode;
                 $formData['employment_status'] = $propertyObj->tenantOccupation;
                 if ($propertyObj->buildingsSumInsured == 0) {
                     $formData['buildings_cover'] = "";
                 } else {
                     $formData['buildings_cover'] = $propertyObj->buildingsSumInsured;
                     $formData['comprehensive_buildings_insurance'] = 1;
                 }
                 if ($propertyObj->buildingsAccidentalDamage == 'Yes') {
                     $formData['buildings_accidental_damage'] = 1;
                 } else {
                     $formData['buildings_accidental_damage'] = 0;
                 }
                 if ($propertyObj->buildingsNilExcess == 'Yes') {
                     $formData['buildings_nil_excess'] = 1;
                 } else {
                     $formData['buildings_nil_excess'] = 0;
                 }
                 if ($propertyObj->contentsSumInsured == 0) {
                     $formData['contents_cover'] = "";
                 } else {
                     $formData['contents_cover'] = $propertyObj->contentsSumInsured;
                     $formData['full_contents_insurance'] = 1;
                 }
                 if ($propertyObj->contentsAccidentalDamage == 'Yes') {
                     $formData['contents_accidental_damage'] = 1;
                 } else {
                     $formData['contents_accidental_damage'] = 0;
                 }
                 if ($propertyObj->contentsNilExcess == 'Yes') {
                     $formData['contents_nil_excess'] = 1;
                 } else {
                     $formData['contents_nil_excess'] = 0;
                 }
                 if ($propertyObj->limitedContents == 'Yes') {
                     $formData['limited_contents'] = 1;
                 } else {
                     $formData['limited_contents'] = 0;
                 }
                 // Populate the form
                 $pageForm->populate($formData);
                 break;
             case "bankInterestDialog":
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $propertyArray = $propertyObjects->toArray();
                 $optionList = array('' => '--- please select ---');
                 foreach ($propertyArray as $property) {
                     $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode'];
                 }
                 // Get the subform element for property address that the bank may have interest in
                 $propertyAddressSelect = $pageForm->getSubForm('subform_bank-details-form')->getElement('bank_property');
                 $propertyAddressSelect->setMultiOptions($optionList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Property not in list'));
                 $propertyAddressSelect->addValidator($validator, true);
                 // Set the selected to 0
                 $propertyAddressSelect->setValue('0');
                 // Now fetch any bank interests we have already stored
                 $bankInterestManager = new Manager_Insurance_Portfolio_BankInterest();
                 $this->view->interestList = $bankInterestManager->fetchAllInterests($customerReferenceNumber);
                 $pageForm->populate($formData);
                 break;
             case "additionalDialog":
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $propertyArray = $propertyObjects->toArray();
                 $optionList = array('' => '--- please select ---');
                 foreach ($propertyArray as $property) {
                     $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode'];
                 }
                 // Get the subform element for property address that the bank may have interest in
                 $propertyAddressSelect = $pageForm->getElement('property');
                 $propertyAddressSelect->setMultiOptions($optionList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Not in list'));
                 $propertyAddressSelect->addValidator($validator, true);
                 // Set the selected to 0
                 $propertyAddressSelect->setValue('0');
                 // Now fetch any Additionals we have already stored
                 $manager = new Manager_Insurance_Portfolio_AdditionalInformation();
                 $qid = $_GET['qid'];
                 $array = $manager->fetchAllByRefNo($customerReferenceNumber, $qid);
                 $this->view->additionalList = $array;
                 $pageForm->populate($formData);
                 break;
             case "claimsDialog":
                 $propertyManager = new Manager_Insurance_Portfolio_Property();
                 $propertyObjects = $propertyManager->fetchAllProperties($customerReferenceNumber);
                 $propertyArray = $propertyObjects->toArray();
                 $optionList = array('' => '--- please select ---');
                 foreach ($propertyArray as $property) {
                     $optionList[$property['id']] = $property['address1'] . " " . $property['address2'] . " " . $property['address3'] . " " . $property['postcode'];
                 }
                 // Get the form element for property address
                 $propertyAddressSelect = $pageForm->getSubForm('subform_previous-claims-form')->getElement('claim_property');
                 $propertyAddressSelect->setMultiOptions($optionList);
                 $validator = new Zend_Validate_InArray(array('haystack' => array_keys($optionList)));
                 $validator->setMessages(array(Zend_Validate_InArray::NOT_IN_ARRAY => 'Not in list'));
                 $propertyAddressSelect->addValidator($validator, true);
                 // Set the selected to 0
                 $propertyAddressSelect->setValue('0');
                 $claimTypeList = array('' => '--- please select ---');
                 $claimTypesSelect = $pageForm->getSubForm('subform_previous-claims-form')->getElement('claim_type');
                 $claimTypes = new Datasource_Insurance_PreviousClaimTypes();
                 $claimTypeObjects = $claimTypes->getPreviousClaimTypes(Model_Insurance_ProductNames::LANDLORDSPLUS);
                 foreach ($claimTypeObjects as $ClaimType) {
                     $claimTypeList[$ClaimType->getClaimTypeID()] = $ClaimType->getClaimTypeText();
                 }
                 $claimTypesSelect->setMultiOptions($claimTypeList);
                 $pageForm->populate($formData);
                 // Now fetch any claims we have already stored
                 $claimsManager = new Manager_Insurance_Portfolio_PreviousClaims();
                 //$array = $claimsManager->fetchAllClaims($customerReferenceNumber);
                 $this->view->claimsList = $claimsManager->fetchAllClaims($customerReferenceNumber);
                 $pageForm->populate($formData);
                 break;
         }
     }
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     $tooFarAhead = false;
     return true;
 }