Exemple #1
0
 public function testRemovingFormItemsShouldNotRaiseExceptionsDuringIteration()
 {
     $this->setupElements();
     $bar = $this->form->bar;
     $this->form->removeElement('bar');
     try {
         foreach ($this->form as $item) {
         }
     } catch (Exception $e) {
         $this->fail('Exceptions should not be raised by iterator when elements are removed; error message: ' . $e->getMessage());
     }
     $this->form->addElement($bar);
     $this->form->addDisplayGroup(array('baz', 'bar'), 'bazbar');
     $this->form->removeDisplayGroup('bazbar');
     try {
         foreach ($this->form as $item) {
         }
     } catch (Exception $e) {
         $this->fail('Exceptions should not be raised by iterator when elements are removed; error message: ' . $e->getMessage());
     }
     $subForm = new Zend_Form_SubForm();
     $subForm->addElements(array('foo' => 'text', 'bar' => 'text'));
     $this->form->addSubForm($subForm, 'page1');
     $this->form->removeSubForm('page1');
     try {
         foreach ($this->form as $item) {
         }
     } catch (Exception $e) {
         $this->fail('Exceptions should not be raised by iterator when elements are removed; error message: ' . $e->getMessage());
     }
 }
 /**
  * Explicitly removes and re-adds elements to the provided form to
  * ensure that the form re-builds the element order.
  *
  * Due to a bug this is required if the order of an element is
  * changed after the internal form index was created:
  * {@link http://framework.zend.com/issues/browse/ZF-9946}
  *
  * @param Zend_Form $form
  * @param array(Zend_Form_Element|Zend_Form|Zend_Form_DisplayGroup) $elements
  */
 protected function reAssignElements(Zend_Form $form, array $elements)
 {
     $elementsByType = $this->categorizeElements($elements);
     foreach ($elementsByType['elements'] as $element) {
         /* @var $element Zend_Form_Element */
         $form->removeElement($element->getName());
         $form->addElement($element);
     }
     foreach ($elementsByType['subForms'] as $subForm) {
         /* @var $subForm Zend_Form */
         $form->removeSubForm($subForm->getName());
         $form->addSubForm($subForm, $subForm->getName());
     }
     foreach ($elementsByType['displayGroups'] as $displayGroup) {
         /* @var $displayGroup Zend_Form_DisplayGroup */
         $form->removeDisplayGroup($displayGroup->getName());
         $form->addDisplayGroup($displayGroup->getElements(), $displayGroup->getName());
     }
 }
Exemple #3
0
 /**
  * Process all information forms related
  * First we check for permissions to add, edit, delete
  * And then the request->isPost. If true we process the data
  *
  * @return Bvb_Grid_Deploy_Table
  */
 protected function _processForm()
 {
     if (!$this->getSource()->hasCrud()) {
         return false;
     }
     if ($this->getInfo("add,allow") == 1) {
         $this->_allowAdd = 1;
     }
     if ($this->getInfo("delete,allow") == 1) {
         $this->_allowDelete = 1;
     }
     if ($this->getInfo("edit,allow") == 1) {
         $this->_allowEdit = 1;
     }
     if ($this->_allowEdit == 1 || $this->_allowDelete == 1) {
         $dec = $this->getParam('comm');
     }
     /**
      * Remove if there is something to remove
      */
     if ($this->_allowDelete == 1) {
         self::_deleteRecord($dec);
     }
     $opComm = $this->getParam('comm');
     $mode = $this->getParam('edit') ? 'edit' : 'add';
     //Check if the request method is POST
     if ($this->getRequest()->isPost() && $this->getRequest()->getPost('zfg_form_edit' . $this->getGridId()) == 1) {
         foreach ($this->_form->getSubForms() as $key => $form) {
             if (isset($_POST[$key]['ZFIGNORE']) && $_POST[$key]['ZFIGNORE'] == 1) {
                 $this->_form->removeSubForm($key);
             }
         }
         if (count($this->_form->getSubForms()) == 0) {
             $this->_redirect($this->getUrl(array('zfg_csrf', 'add', 'zfg_form_edit', 'form_submit')));
         }
         if ($this->_form->isValid($_POST)) {
             $post = array();
             foreach ($this->_form->getSubForms() as $key => $value) {
                 foreach ($value->getElements() as $el) {
                     $fieldValue = $el->getValue();
                     $post[$key][$el->getName()] = is_array($fieldValue) ? implode(',', $fieldValue) : $fieldValue;
                 }
                 unset($post[$key]['ZFIGNORE']);
             }
             $addNew = false;
             if (isset($_POST['saveAndAdd' . $this->getGridId()])) {
                 $this->_gridSession->noErrors = true;
                 $addNew = true;
             }
             unset($post['form_submit' . $this->getGridId()]);
             unset($post['zfg_form_edit' . $this->getGridId()]);
             unset($post['form_reset' . $this->getGridId()]);
             unset($post['zfg_csrf' . $this->getGridId()]);
             unset($post['saveAndAdd' . $this->getGridId()]);
             // Process data
             if ($mode == 'add') {
                 try {
                     foreach ($this->_form->getSubForms() as $key => $value) {
                         if ($this->_crud->getUseVerticalInputs() === false && $key == 0) {
                             continue;
                         }
                         $sendCall = array(&$post[$key], $this->getSource());
                         if (null !== $this->_callbackBeforeInsert) {
                             call_user_func_array($this->_callbackBeforeInsert, $sendCall);
                         }
                         //Let's see if the field is nullable and empty
                         //If so, we need to remove it from the array
                         $tableFields = $this->getSource()->getDescribeTable($this->_crudTable);
                         foreach (array_keys($post[$key]) as $field) {
                             if ($tableFields[$field]['NULLABLE'] == 1 && strlen($post[$key][$field]) == 0) {
                                 unset($post[$key][$field]);
                             }
                         }
                         if ($this->_crudTableOptions['add'] == true) {
                             $post[$key] = array_merge($post[$key], $this->_crudOptions['addForce']);
                             $sendCall[] = $this->getSource()->insert($this->_crudTable, $post[$key]);
                         }
                         if (null !== $this->_callbackAfterInsert) {
                             call_user_func_array($this->_callbackAfterInsert, $sendCall);
                         }
                         unset($this->_gridSession->post[$key]);
                     }
                     $this->_gridSession->message = $this->__('Record saved');
                     $this->_gridSession->messageOk = true;
                     if (isset($post['saveAndAdd' . $this->getGridId()])) {
                         $this->_gridSession->_noForm = 0;
                     } else {
                         $this->_gridSession->_noForm = 1;
                     }
                     $this->_gridSession->correct = 1;
                     $this->_removeFormParams(array('add' . $this->getGridId() => '1'));
                     if ($addNew === true) {
                         $finalUrl = '/add' . $this->getGridId() . '/1';
                     } else {
                         $finalUrl = '';
                     }
                     $this->_redirect($this->getUrl() . $finalUrl);
                     die;
                 } catch (Zend_Exception $e) {
                     $this->_gridSession->messageOk = false;
                     $this->_gridSession->message = $this->__('Error saving record: ') . $e->getMessage();
                     $this->_gridSession->formSuccess = 0;
                     $this->_gridSession->formPost = 1;
                     $this->_gridSession->_noForm = 0;
                     $this->_gridSession->correct = 0;
                     $this->_removeFormParams();
                     $this->_redirect($this->getUrl());
                 }
             }
             // Process data
             if ($mode == 'edit') {
                 try {
                     foreach ($this->_form->getSubForms() as $key => $value) {
                         if ($this->_crud->getUseVerticalInputs() === false && $key == 0) {
                             continue;
                         }
                         $pks = $this->getSource()->getIdentifierColumns($this->_data['table'], $this->_data['schema']);
                         if (isset($post[$key]['ZFPK'])) {
                             if (strpos($post[$key]['ZFPK'], '-')) {
                                 $allIds = explode('-', $post[$key]['ZFPK']);
                                 $i = 0;
                                 foreach ($allIds as $fIds) {
                                     $condition[$pks[$i]] = $fIds;
                                     $i++;
                                 }
                             } else {
                                 $condition[$pks[0]] = $post[$key]['ZFPK'];
                             }
                             $queryUrl = $condition;
                             unset($post[$key]['ZFPK']);
                         }
                         $post[$key] = array_merge($post[$key], $this->_crudOptions['editForce']);
                         $queryUrl = array_merge($queryUrl, $this->_crudOptions['editAddCondition']);
                         $oldFieldValues = $this->getSource()->getRecord($this->_data['table'], $this->getIdentifierColumnsFromUrl());
                         foreach ($oldFieldValues as $field => $value) {
                             if (!isset($post[$key][$field])) {
                                 unset($oldFieldValues[$field]);
                             }
                         }
                         $sendCall = array($oldFieldValues, $this->getSource(), &$queryUrl);
                         if (null !== $this->_callbackBeforeUpdate) {
                             call_user_func_array($this->_callbackBeforeUpdate, $sendCall);
                         }
                         if ($this->_crudTableOptions['edit'] == true) {
                             $this->getSource()->update($this->_crudTable, $post[$key], $queryUrl);
                         }
                         if (null !== $this->_callbackAfterUpdate) {
                             $sendCall = array(&$post[$key], $this->getSource(), &$queryUrl);
                             call_user_func_array($this->_callbackAfterUpdate, $sendCall);
                         }
                     }
                     $this->_gridSession->message = $this->__('Record saved');
                     $this->_gridSession->messageOk = true;
                     $this->_gridSession->_noForm = 1;
                     $this->_gridSession->correct = 1;
                     unset($this->_gridSession->post);
                     $this->_removeFormParams(array('comm' . $this->getGridId() => '', 'edit' . $this->getGridId() => '', '
                               zfmassedit' => ''));
                     $this->_redirect($this->getUrl());
                 } catch (Zend_Exception $e) {
                     $this->_gridSession->messageOk = false;
                     $this->_gridSession->message = $this->__('Error updating record: ') . $e->getMessage();
                     $this->_gridSession->formSuccess = 0;
                     $this->_gridSession->formPost = 1;
                     $this->_gridSession->_noForm = 0;
                     $this->_gridSession->correct = 0;
                     $this->_removeFormParams();
                     $this->_redirect($this->getUrl());
                 }
             }
         } else {
             $this->_gridSession->post = $_POST;
             foreach ($this->_form->getSubForms() as $key => $value) {
                 $this->_gridSession->errors[$key] = $value->getMessages();
             }
             $this->_gridSession->message = $this->__('Validation failed');
             $this->_gridSession->messageOk = false;
             $this->_gridSession->formSuccess = 0;
             $this->_gridSession->formPost = 1;
             $this->_gridSession->_noForm = 0;
             $this->_gridSession->correct = 0;
             $this->_removeFormParams();
         }
     }
 }
Exemple #4
0
 /**
  * Process all information forms related
  * First we check for permissions to add, edit, delete
  * And then the request->isPost. If true we process the data
  *
  * @return Bvb_Grid_Deploy_Table
  */
 protected function _processForm()
 {
     if (!$this->getSource()->hasCrud()) {
         return false;
     }
     if ($this->getInfo("add,allow") == 1) {
         $this->_allowAdd = 1;
     }
     if ($this->getInfo("delete,allow") == 1) {
         $this->_allowDelete = 1;
     }
     if ($this->getInfo("edit,allow") == 1) {
         $this->_allowEdit = 1;
     }
     /**
      * Remove if there is something to remove
      */
     if ($this->_allowDelete == 1 && ($this->getParam('delete') || $this->getParam('zfmassremove')) && !$this->getParam('detail')) {
         self::_deleteRecord();
     }
     $mode = $this->getParam('edit') ? 'edit' : 'add';
     //Check if the request method is POST
     if ($this->getRequest()->isPost() && $this->getRequest()->getPost('zfg_form_edit' . $this->getGridId()) == 1) {
         foreach ($this->_form->getSubForms() as $key => $form) {
             if (isset($_POST[$key]['ZFIGNORE']) && $_POST[$key]['ZFIGNORE'] == 1) {
                 $this->_form->removeSubForm($key);
             }
         }
         if (count($this->_form->getSubForms()) == 0) {
             $this->_redirect($this->getUrl(array('zfg_csrf', 'add', 'zfg_form_edit', 'form_submit')));
         }
         if ($this->_form->isValid($_POST)) {
             $post = array();
             foreach ($this->_form->getSubForms() as $key => $value) {
                 foreach ($value->getElements() as $el) {
                     if ($el->getIgnore()) {
                         continue;
                     }
                     $fieldValue = $el->getValue();
                     $post[$key][$el->getName()] = is_array($fieldValue) ? implode(',', $fieldValue) : $fieldValue;
                 }
                 unset($post[$key]['ZFIGNORE']);
             }
             $addNew = false;
             if (isset($_POST['saveAndAdd' . $this->getGridId()])) {
                 $this->_gridSession->noErrors = true;
                 $addNew = true;
             }
             unset($post['form_submit' . $this->getGridId()]);
             unset($post['zfg_form_edit' . $this->getGridId()]);
             unset($post['form_reset' . $this->getGridId()]);
             unset($post['zfg_csrf' . $this->getGridId()]);
             unset($post['saveAndAdd' . $this->getGridId()]);
             // Process data
             if ($mode == 'add') {
                 $this->getSource()->beginTransaction();
                 try {
                     foreach ($this->_form->getSubForms() as $key => $value) {
                         if ($this->_crud->getUseVerticalInputs() === false && $key == 0) {
                             continue;
                         }
                         //Let's see if the field is nullable and empty
                         //If so, we need to remove it from the array
                         $tableFields = $this->getSource()->getDescribeTable($this->_crudTable);
                         foreach (array_keys($post[$key]) as $field) {
                             if (!isset($tableFields[$field])) {
                                 continue;
                             }
                             if ($tableFields[$field]['NULLABLE'] == 1 && strlen($post[$key][$field]) == 0) {
                                 $post[$key][$field] = new Zend_Db_Expr("NULL");
                             }
                         }
                         if (count($post[$key]) == 0) {
                             throw new Bvb_Grid_Exception($this->__('No values to insert'));
                         }
                         $post[$key] = array_merge($post[$key], $this->_crudOptions['addForce']);
                         $this->emitEvent('crud.before_insert', array('table' => &$this->_crudTable, 'connectionId' => $this->getSource()->getConnectionId(), 'values' => &$post[$key]));
                         if ($this->_crudTableOptions['add'] == true) {
                             $insertId = $this->getSource()->insert($this->_crudTable, $post[$key]);
                         } else {
                             $insertId = '';
                         }
                         $this->emitEvent('crud.after_insert', array('table' => &$this->_crudTable, 'connectionId' => $this->getSource()->getConnectionId(), 'values' => &$post[$key], 'insertId' => $insertId));
                         unset($this->_gridSession->post[$key]);
                     }
                     $this->getSource()->commit();
                     $this->_gridSession->message = $this->__('Record saved');
                     $this->_gridSession->messageOk = true;
                     if (isset($post['saveAndAdd' . $this->getGridId()])) {
                         $this->_gridSession->_noForm = 0;
                     } else {
                         $this->_gridSession->_noForm = 1;
                     }
                     $this->_gridSession->correct = 1;
                     $this->_removeFormParams(array('add' . $this->getGridId() => '1'));
                     if ($addNew === true) {
                         $finalUrl = '/add/1';
                     } else {
                         $finalUrl = '';
                     }
                     $this->_redirect($this->getUrl() . $finalUrl);
                 } catch (Exception $e) {
                     $this->_gridSession->messageOk = false;
                     $this->_gridSession->message = $this->__('Error saving record: ') . $e->getMessage();
                     $this->_gridSession->formSuccess = 0;
                     $this->_gridSession->formPost = 1;
                     $this->_gridSession->_noForm = 0;
                     $this->_gridSession->correct = 0;
                     $this->getForm(1)->markAsError();
                     $this->getSource()->rollBack();
                     $this->_removeFormParams();
                     $this->_redirect($this->getUrl());
                 }
             }
             // Process data
             if ($mode == 'edit') {
                 try {
                     $this->getSource()->beginTransaction();
                     foreach ($this->_form->getSubForms() as $key => $value) {
                         if ($this->_crud->getUseVerticalInputs() === false && $key == 0) {
                             continue;
                         }
                         $tableFields = $this->getSource()->getDescribeTable($this->_crudTable);
                         foreach (array_keys($post[$key]) as $field) {
                             if ($tableFields[$field]['NULLABLE'] == 1 && strlen($post[$key][$field]) == 0) {
                                 $post[$key][$field] = new Zend_Db_Expr("NULL");
                             }
                         }
                         $pks = $this->getSource()->getIdentifierColumns($this->_data['table'], $this->_data['schema']);
                         if (isset($post[$key]['ZFPK'])) {
                             if (strpos($post[$key]['ZFPK'], '-')) {
                                 $allIds = explode('-', $post[$key]['ZFPK']);
                                 $i = 0;
                                 foreach ($allIds as $fIds) {
                                     $condition[$pks[$i]] = $fIds;
                                     $i++;
                                 }
                             } else {
                                 $condition[$pks[0]] = $post[$key]['ZFPK'];
                             }
                             $queryUrl = $condition;
                             unset($post[$key]['ZFPK']);
                         }
                         $post[$key] = array_merge($post[$key], $this->_crudOptions['editForce']);
                         $queryUrl = array_merge($queryUrl, $this->_crudOptions['editAddCondition']);
                         $oldValues = $this->getSource()->getRecord($this->_crudTable, $condition);
                         $this->emitEvent('crud.before_update', array('table' => &$this->_crudTable, 'connectionId' => $this->getSource()->getConnectionId(), 'newValues' => &$post[$key], 'oldValues' => &$oldValues, 'condition' => &$condition));
                         if (count($post[$key]) == 0) {
                             throw new Bvb_Grid_Exception($this->__('No values to update'));
                         }
                         if ($this->_crudTableOptions['edit'] == true) {
                             $this->getSource()->update($this->_crudTable, $post[$key], $queryUrl);
                         }
                         $newValues = $this->getSource()->getRecord($this->_crudTable, $condition);
                         $this->emitEvent('crud.after_update', array('table' => &$this->_crudTable, 'connectionId' => $this->getSource()->getConnectionId(), 'newValues' => &$newValues, 'oldValues' => &$oldValues, 'condition' => &$condition));
                     }
                     $this->getSource()->commit();
                     $this->_gridSession->message = $this->__('Record saved');
                     $this->_gridSession->messageOk = true;
                     $this->_gridSession->_noForm = 1;
                     $this->_gridSession->correct = 1;
                     unset($this->_gridSession->post);
                     $this->_removeFormParams(array('edit' . $this->getGridId() => '', '
                               zfmassedit' => ''));
                     $this->_redirect($this->getUrl());
                 } catch (Exception $e) {
                     $this->_gridSession->messageOk = false;
                     $this->_gridSession->message = $this->__('Error updating record: ') . $e->getMessage();
                     $this->_gridSession->formSuccess = 0;
                     $this->_gridSession->formPost = 1;
                     $this->_gridSession->_noForm = 0;
                     $this->_gridSession->correct = 0;
                     $this->getSource()->rollBack();
                     $this->getForm(1)->markAsError();
                     $this->_removeFormParams();
                     $this->_redirect($this->getUrl());
                 }
             }
         } else {
             $this->_gridSession->post = $_POST;
             foreach ($this->_form->getSubForms() as $key => $value) {
                 $this->_gridSession->errors[$key] = $value->getMessages();
             }
             $this->_gridSession->message = $this->__('Validation failed');
             $this->_gridSession->messageOk = false;
             $this->_gridSession->formSuccess = 0;
             $this->_gridSession->formPost = 1;
             $this->_gridSession->_noForm = 0;
             $this->_gridSession->correct = 0;
             $this->_removeFormParams();
         }
     }
 }
 /**
  * Helper function to populate the zend form elements with database data
  *
  * @param Zend_Form $pageForm form definition for this step
  * @param int $stepNum current step number
  *
  * @return void
  */
 private function _formStepCommonPopulate($pageForm, $stepNum)
 {
     $this->view->stepNum = $stepNum;
     $this->view->stepMax = $this->_stepMax;
     // Check to see if the user is trying to skip ahead in the quote
     $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
     $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('/landlords/insurance-quote/step' . $lastCompleted);
         return false;
     }
     if ($stepNum > 1) {
         // Before we do ANYTHING we need to check to see if the email address entered matches a customer record
         // we already have - if it does we need to ask them to login before they proceed.
         $customerReferenceNumber = $this->_customerReferenceNumber;
         $customerManager = new Manager_Core_Customer();
         $legacyCustomer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $customerReferenceNumber);
         $emailAddress = $legacyCustomer->getEmailAddress();
         $customer = $customerManager->getCustomerByEmailAddress($emailAddress);
         if ($customer) {
             // There is already a customer entry for this email address - so we need to see if they are logged in
             // if not we need to force them to login
             $auth = Zend_Auth::getInstance();
             $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
             if ($auth->hasIdentity()) {
                 $loggedInEmail = $auth->getStorage()->read()->email_address;
                 if ($loggedInEmail != $customer->getEmailAddress()) {
                     // They are logged in but not who they should be to do this quote
                     $this->_helper->redirector->gotoUrl('/account/login?refer=landlords-insurance&step=' . $stepNum);
                     return false;
                 }
             } else {
                 // TODO: Check that removing the login redirection will not break other processes
                 // They aren't logged in and need to
                 /*$this->_helper->redirector->gotoUrl('/account/login?refer=landlords-insurance&step='. $stepNum);
                 		return false;*/
             }
         }
     }
     $formData = array();
     // If step 1 and not in session (so producing a quick quote) - we need to pre-populate
     // a few bits if the customer is already logged into the site
     if ($stepNum == 1 && !isset($pageSession->CustomerRefNo)) {
         $auth = Zend_Auth::getInstance();
         $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
         if ($auth->hasIdentity()) {
             // Customer is logged in and starting a new quote - so we need to pre-populate the customers details from stored details
             $customerID = $auth->getStorage()->read()->id;
             $customerManager = new Manager_Core_Customer();
             $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID);
             $formData['title'] = $customer->getTitle();
             $formData['first_name'] = $customer->getFirstName();
             $formData['last_name'] = $customer->getLastName();
             $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
             $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
             $formData['email_address'] = $customer->getEmailAddress();
             $formData['date_of_birth_at'] = $customer->getDateOfBirthAt();
             $pageForm->populate($formData);
         }
     }
     if (isset($this->_quoteID) && $this->_quoteID > 0) {
         $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($this->_quoteID);
         $premiums = $quoteManager->calculatePremiums();
         if ($premiums != '') {
             $this->view->premiums = array('annual' => $premiums['totalGrossAnnualPremium'] + $premiums['totalGrossAnnualIPT'], 'monthly' => $premiums['totalGrossMonthlyPremium'] + $premiums['totalGrossMonthlyIPT']);
             $this->view->premiumsFull = $premiums;
         }
         $fees = $quoteManager->getFees();
         $this->view->fees = $fees;
         switch ($stepNum) {
             case 1:
                 $customerManager = new Manager_Core_Customer();
                 $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteManager->getLegacyCustomerReference());
                 // Populate the customer details
                 $titleOptions = LandlordsInsuranceQuote_Form_Subforms_PersonalDetails::$titles;
                 if (in_array($customer->getTitle(), $titleOptions)) {
                     $formData['title'] = $customer->getTitle();
                 } else {
                     $formData['title'] = "Other";
                     $formData['other_title'] = $customer->getTitle();
                 }
                 $formData['first_name'] = $customer->getFirstName();
                 $formData['last_name'] = $customer->getLastName();
                 $formData['phone_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE1);
                 $formData['mobile_number'] = $customer->getTelephone(Model_Core_Customer::TELEPHONE2);
                 $formData['email_address'] = $customer->getEmailAddress();
                 $dob = $customer->getDateOfBirthAt();
                 if (null != $dob && '0000-00-00' != $dob) {
                     $formData['date_of_birth_at'] = Application_Core_Utilities::mysqlDateToUk($dob);
                 }
                 // Populate the correspondence address details
                 $formData['cor_address_line1'] = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE1);
                 $formData['cor_address_line2'] = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE2);
                 $formData['cor_address_line3'] = $customer->getAddressLine(Model_Core_Customer::ADDRESSLINE3);
                 $formData['cor_address_postcode'] = $customer->getPostcode();
                 $formData['country'] = $customer->getCountry();
                 // Populate the insured property address details
                 $properties = $quoteManager->getProperties();
                 if (count($properties) > 0) {
                     $formData['ins_address_line1'] = $properties[0]['line_1'];
                     $formData['ins_address_line2'] = $properties[0]['line_2'];
                     $formData['ins_address_line3'] = $properties[0]['town'];
                     $formData['ins_address_postcode'] = $properties[0]['postcode'];
                     $formData['owned_for'] = $properties[0]['ownership_length_id'];
                     $formData['no_claims'] = $properties[0]['no_claims_years_id'];
                     $formData['tenants_type'] = $properties[0]['tenant_type_id'];
                     $formData['have_letting_agent'] = $quoteManager->getAgentSchemeNumber() != Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber()) ? 'yes' : 'no';
                     $formData['through_letting_agent'] = $properties[0]['letting_agent_managed'] ? 'yes' : 'no';
                     // Check to see if this postcode is in a flood risk area - if it is then populate the exclude flood cover data
                     // Populating this will also cause the question to be shown on the front end
                     $landlordsRiskAreas = new Datasource_Insurance_LandlordsPlus_RiskAreas();
                     $riskAreas = $landlordsRiskAreas->getByPostcode($properties[0]['postcode']);
                     if ($riskAreas['floodArea'] == '600') {
                         $formData['exclude_flood_cover'] = $properties[0]['exclude_flood_cover'] ? 'no' : 'yes';
                         // Backwards true/false stuff - I'm sooo sorry :(
                     }
                 }
                 // Populate agent details if one has been chosen
                 $agentSchemeNumber = Manager_Core_Agent::filterAsn($quoteManager->getAgentSchemeNumber());
                 $defaultASN = $this->_params->homelet->defaultAgent;
                 if ($formData['have_letting_agent'] == 'yes') {
                     $agents = new Datasource_Core_Agents();
                     $agent = $agents->getAgent($agentSchemeNumber);
                     $formData['letting_agent_name'] = $agent->name;
                     $formData['letting_agent_town'] = $agent->town;
                     $formData['letting_agent_asn'] = $agent->agentSchemeNumber;
                     // Fix for Redmine Ref. #10511:
                     $agentDropdown = $pageForm->subform_lettingagent->letting_agent;
                     $agentDropdown->setMultiOptions(array($agent->agentSchemeNumber => $agent->name . ', ' . $agent->town));
                     $formData['letting_agent'] = $agent->agentSchemeNumber;
                 }
                 // Load the policy start date
                 $startDate = $quoteManager->getStartDate();
                 if ($startDate != '' && $startDate != '0000-00-00') {
                     $formData['policy_start'] = substr($startDate, 8, 2) . '/' . substr($startDate, 5, 2) . '/' . substr($startDate, 0, 4);
                 }
                 // If step1 has been marked complete - we can assume they said yes to the IDD question
                 $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     $formData['idd'] = true;
                 }
                 // Data Protection section
                 $customerReferenceNumber = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
                 $dpaManager = new Manager_Core_DataProtection();
                 $dpaItems = $dpaManager->getItems($customerReferenceNumber, Model_Core_DataProtection_ItemEntityTypes::INSURANCE);
                 foreach ($dpaItems 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'] = 0;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             } else {
                                 $formData['dpa_sms_email'] = 1;
                                 // For Redmine Ref #8003, "Updated marketing preference questions on online quotes"
                             }
                             break;
                         case Model_Core_DataProtection_ItemConstraintTypes::MARKETING_BY_THIRDPARTY:
                             if ($currentItem->isAllowed) {
                                 $formData['dpa_resale'] = 1;
                             } else {
                                 $formData['dpa_resale'] = 0;
                             }
                             break;
                     }
                 }
             case 2:
                 // If step2 has been marked complete - we can assume they said no to the questions unless
                 // they've been set in the quote manager
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     $formData['need_building_insurance'] = 'no';
                     $formData['need_contents_insurance'] = 'no';
                 }
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER)) {
                     $formData['need_building_insurance'] = 'yes';
                     $productMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER);
                     $formData['building_built'] = $productMeta['build_year'];
                     $formData['building_bedrooms'] = $productMeta['bedroom_quantity'];
                     $formData['building_type'] = $productMeta['building_type'];
                     $formData['building_insurance_excess'] = $productMeta['excess'];
                     $formData['building_accidental_damage'] = $productMeta['accidental_damage'];
                     $quote = $quoteManager->getModel();
                     if ((int) $productMeta['rebuild_value'] > 0) {
                         // There's a manually entered rebuild value - need to work out if it is because they
                         // chose £500k+ - or if it's because we don't have a dsi
                         $premiums = $quoteManager->calculatePremiums();
                         if ($premiums['calculatedDSIValue'] > 0) {
                             $formData['override_dsi'] = 1;
                         }
                         $formData['building_value'] = $productMeta['rebuild_value'];
                     }
                 }
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER) || $quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::UNFURNISHED_CONTENTS_COVER)) {
                     $formData['need_contents_insurance'] = 'yes';
                     if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER)) {
                         $formData['property_furnished'] = 'yes';
                         $productMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER);
                         $formData['contents_amount'] = $productMeta['cover_amount'];
                         $formData['contents_excess'] = $productMeta['excess'];
                         $formData['contents_accidental_damage'] = $productMeta['accidental_damage'];
                     } else {
                         $formData['property_furnished'] = 'no';
                     }
                 }
                 break;
             case 3:
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     $formData['need_emergency_assistance'] = 'no';
                     $formData['need_prestige_rent_guarantee'] = 'no';
                     $formData['need_legal_expenses'] = 'no';
                     $formData['need_boiler_heating'] = 'no';
                 }
                 // If we have contents/buildings cover then EAS is already included for free so we can hide the form
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BUILDING_COVER) || $quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::CONTENTS_COVER)) {
                     // Change the subforms view script to one that just says it's already included for free
                     // yeah yeah.. this aint pretty :(
                     $emergencyAssistanceForm = $pageForm->getSubForm('subform_emergencyassistance');
                     $emergencyAssistanceForm->setDecorators(array(array('ViewScript', array('viewScript' => 'subforms/emergency-assistance-free.phtml'))));
                     if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::BOILER_HEATING)) {
                         $formData['need_boiler_heating'] = 'yes';
                     }
                 } else {
                     // We can allow stand-alone EAS - so we hide the boiler and heating section
                     // yes... this is waaay too complex... I know :(
                     $pageForm->removeSubForm('subform_boilerheating');
                     if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::EMERGENCY_ASSISTANCE)) {
                         $formData['need_emergency_assistance'] = 'yes';
                     }
                 }
                 if ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE)) {
                     $formData['need_prestige_rent_guarantee'] = 'yes';
                     $productMeta = $quoteManager->getProductMeta(Manager_Insurance_LandlordsPlus_Quote::RENT_GUARANTEE);
                     $formData['rent_amount'] = $productMeta['monthly_rent'];
                 } elseif ($quoteManager->hasProduct(Manager_Insurance_LandlordsPlus_Quote::LEGAL_EXPENSES)) {
                     $formData['need_legal_expenses'] = 'yes';
                 }
                 break;
             case 4:
                 if (isset($pageSession->completed[$stepNum]) && $pageSession->completed[$stepNum] == true) {
                     // Load underwriting answers from the database as they've already been answered
                     $answersManager = new Manager_Insurance_Answers();
                     $quote = $quoteManager->getModel();
                     $policyNumber = $quote->legacyID;
                     $customerReferenceNumber = $quote->legacyCustomerID;
                     $answers = $answersManager->getUnderwritingAnswers($policyNumber);
                     foreach ($answers as $answer) {
                         switch ($answer->getQuestionNumber()) {
                             case '53':
                                 $formData['declaration1'] = $answer->getAnswer();
                                 break;
                             case '54':
                                 $formData['declaration2'] = $answer->getAnswer();
                                 break;
                             case '55':
                                 $formData['declaration2b'] = $answer->getAnswer();
                                 break;
                             case '56':
                                 $formData['declaration2c'] = $answer->getAnswer();
                                 break;
                             case '57':
                                 $formData['declaration2d'] = $answer->getAnswer();
                                 break;
                             case '58':
                                 $formData['declaration3'] = $answer->getAnswer();
                                 break;
                             case '59':
                                 $formData['declaration4'] = $answer->getAnswer();
                                 break;
                             case '60':
                                 $formData['declaration6'] = $answer->getAnswer();
                                 break;
                             case '61':
                                 $formData['declaration7'] = $answer->getAnswer();
                                 break;
                             case '62':
                                 $formData['declaration8'] = $answer->getAnswer();
                                 break;
                             case '63':
                                 $formData['declaration9'] = $answer->getAnswer();
                                 break;
                             case '64':
                                 $formData['declaration10'] = $answer->getAnswer();
                                 break;
                         }
                     }
                     // Also need to see if they said yes or no to bank interest on the propery…
                     $bankInterestManager = new Manager_Insurance_LegacyBankInterest();
                     $bankInterestArray = $bankInterestManager->getAllInterests($policyNumber, $customerReferenceNumber);
                     $model = array();
                     if (!empty($bankInterestArray)) {
                         $formData['declaration11'] = 'yes';
                     } else {
                         $formData['declaration11'] = 'no';
                     }
                     // They must have agreed to the declaration or they wouldn't have been able to continue
                     $formData['declaration_confirmation'] = 'yes';
                 }
                 break;
             case 5:
                 // Payment Selection section
                 if (isset($pageSession->paymentSelectionDetails) && is_array($pageSession->paymentSelectionDetails)) {
                     $formData = $pageSession->paymentSelectionDetails;
                 }
                 break;
         }
     }
     $pageForm->populate($formData);
     return true;
 }