/** * Add an element * @param \Foundation\Form\Element */ public function addElement(Element $element) { if (array_key_exists($element->getName(), $this->form->getElements())) { $message = 'An element with the name ' . $element->getName() . ' already exists in this form'; throw new \Foundation\Exception($message); } $this->elements[$element->getName()] = $element; }
public function getForm() { if (is_null($this->_form)) { $this->_form = $this->makeForm(); } //reset the CSRF token on every request so when submission fails token validation doesn't even if the session has timed out $this->_form->setCSRFToken($this->_controller->getCSRFToken()); return $this->_form; }
/** * Get the login form * * @return \Foundation\Form */ public function getLoginForm() { if (is_null($this->_form)) { $this->_form = new \Foundation\Form(); $this->_form->setCSRFToken($this->_controller->getCSRFToken()); $this->_form->setAction($this->_controller->path("login")); $field = $this->_form->newField(); $field->setLegend('Select a user'); $element = $field->newElement('TextInput', 'apiKey'); $element->setLabel('API Key'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $this->_form->newButton('submit', 'Login'); } return $this->_form; }
public function getForm() { if (is_null($this->_form)) { $this->_form = new \Foundation\Form(); $this->_form->setCSRFToken($this->_controller->getCSRFToken()); $this->_form->setAction($this->_controller->getActionPath()); $field = $this->_form->newField(); $field->setLegend($this->_applicationPage->getTitle()); $field->setInstructions($this->_applicationPage->getInstructions()); $element = $field->newElement('RadioList', 'lock'); $element->setLabel('Do you wish to lock your application?'); $element->newItem(0, 'No'); $element->newItem(1, 'Yes'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $this->_form->newButton('submit', 'Submit Application'); } return $this->_form; }
/** * Get the login form * * @return \Foundation\Form */ public function getLoginForm() { if (is_null($this->_form)) { $this->_form = new \Foundation\Form(); $this->_form->setCSRFToken($this->_controller->getCSRFToken()); $this->_form->setAction($this->_controller->path("login")); $field = $this->_form->newField(); $field->setLegend('Select a user'); $element = $field->newElement('SelectList', 'userid'); $element->setLabel('User'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); foreach ($this->_controller->getEntityManager()->getRepository('\\Jazzee\\Entity\\User')->findByName('%', '%') as $user) { if ($user->isActive()) { $element->newItem($user->getId(), "{$user->getLastName()}, {$user->getFirstName()} - {$user->getEmail()}"); } } $this->_form->newButton('submit', 'Login'); } return $this->_form; }
/** * Process post data for all status text forms * @param string $status * @param \Foundation\Form $form */ protected function processStatusForm($status, \Foundation\Form $form) { if ($input = $form->processInput($this->post)) { $func = "setStatus{$status}Text"; $this->_application->{$func}($input->get('message')); $this->_em->persist($this->_application); $this->addMessage('success', 'Message Saved.'); $this->redirectPath('setup/application'); } }
/** * Validate an address with QAS * @param array $postData * @param \Foundation\Form $countryForm * @return \Foundation\Form\Input | false */ protected function validateAddress(array $postData, \Foundation\Form $countryForm) { $countryName = $countryForm->getElementByName('countryName')->getValue(); $country = $countryForm->getElementByName('country')->getValue(); $countriesToValidate = explode(',', $this->_applicationPage->getPage()->getVar('validatedCountries')); //Create the QuickAddress Object and set the engine and picklist type $qas = new \QuickAddress($this->_applicationPage->getPage()->getVar('wsdlAddress')); $qas->setEngineType(QAS_VERIFICATION_ENGINE); $qas->setFlatten(true); $qasCountryCode = $this->getQASCodeForCountry($countryName); $qasLayout = "Database layout"; switch ($postData['type']) { case 'confirmAddress': if ($postData['addressChoice'] == 'validated') { return unserialize(base64_decode($postData['validatedInput'])); } else { if ($postData['addressChoice'] == 'original') { return unserialize(base64_decode($postData['originalInput'])); } else { $input = unserialize(base64_decode($postData['originalInput'])); foreach ($countryForm->getElements() as $formElement) { if ($input->checkIsSet($formElement->getName())) { $formElement->setValue($input->get($formElement->getName())); } } $this->_form = $countryForm; return false; } } break; case 'validate': if (!($input = $countryForm->processInput($postData))) { $this->_form = $countryForm; return false; } //Check to see if this is the second time the user has input this address, //if it is then just use that as the address unverified $sameUserInput = false; if ($str = $input->get('originalInput')) { $str = base64_decode($str); $originalInput = unserialize($str); $sameUserInput = true; foreach (array('address1', 'address2', 'address3', 'city', 'state', 'postalCode', 'country') as $name) { if ($originalInput->get($name) != $input->get($name)) { $sameUserInput = false; break; } } } $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS1)->getId(), $input->get('address1')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS2)->getId(), $input->get('address2')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS3)->getId(), $input->get('address3')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_CITY)->getId(), $input->get('city')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_STATE)->getId(), $input->get('state')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_POSTALCODE)->getId(), $input->get('postalCode')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_COUNTRY)->getId(), $countryName); if ($sameUserInput or !in_array($this->getQASCodeForCountry($countryName), $countriesToValidate) or !$qas->canSearch($qasCountryCode, $qasLayout)->IsOk) { return $input; } $search = array(); $search[0] = $input->get('address1'); $search[1] = $input->get('address2'); $search[2] = $input->get('city'); $search[3] = $input->get('state'); $search[4] = $input->get('postalCode'); //Perform the search itself $result = $qas->search($qasCountryCode, $search, QAS_DEFAULT_PROMPT, $qasLayout); switch ($result->sVerifyLevel) { case 'Verified': case 'InteractionRequired': $originalInput = clone $input; $arr = $result->address->atAddressLines; $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS1)->getId(), $arr[0]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS2)->getId(), $arr[1]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS3)->getId(), $input->get('address3')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_CITY)->getId(), $arr[3]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_STATE)->getId(), $arr[4]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_POSTALCODE)->getId(), $arr[5]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_COUNTRY)->getId(), $countryName); $validatedInput = clone $input; $confirmationForm = new \Foundation\Form(); $confirmationForm->setAction($countryForm->getAction()); $confirmationForm->setCSRFToken($this->_controller->getCSRFToken()); $field = $confirmationForm->newField(); $field->setLegend('Confirm Address'); $element = $field->newElement('RadioList', 'addressChoice'); $element->setLabel('Confirm Address'); $element->newItem('validated', 'Use Our Sugested Address <br />' . $this->formatAddressFromInput($validatedInput)); $element->newItem('original', 'Use Address as Entered<br />' . $this->formatAddressFromInput($originalInput)); $element->newItem('edit', 'Edit the Address you Entered'); $element->setValue('validated'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $confirmationForm->newHiddenElement('type', 'confirmAddress'); $confirmationForm->newHiddenElement('countryName', $countryName); $confirmationForm->newHiddenElement('country', $country); $confirmationForm->newHiddenElement('originalInput', base64_encode(serialize($originalInput))); $confirmationForm->newHiddenElement('validatedInput', base64_encode(serialize($validatedInput))); $confirmationForm->newButton('submit', 'Save'); $this->_form = $confirmationForm; return false; break; case 'Multiple': $this->_controller->addMessage('error', 'We were unable to validate your address.'); $this->_controller->setVar('confirm', true); $countryForm->getElementByName('submit')->setValue('Confirm Address as Entered'); $this->_controller->setVar('originalInput', base64_encode(serialize($input))); $countryForm->newHiddenElement('originalInput', base64_encode(serialize($input))); $this->_controller->setVar('picklist', $result->picklist); $this->_form = $countryForm; break; case 'StreetPartial': case 'PremisesPartial': $this->_controller->addMessage('error', 'We were unable to validate your address. If you are sure this address is correct then click the "Confirm Address as Entered" button.'); $countryForm->getElementByName('address1')->addMessage('Your address is incomplete'); $countryForm->getElementByName('address2')->addMessage('Your address is incomplete'); $countryForm->getElementByName('submit')->setValue('Confirm Address as Entered'); $countryForm->newHiddenElement('originalInput', base64_encode(serialize($input))); $this->_form = $countryForm; break; case 'None': $this->_controller->addMessage('error', 'We were unable to validate your address.'); $countryForm->getElementByName('submit')->setValue('Confirm Address as Entered'); $countryForm->newHiddenElement('originalInput', base64_encode(serialize($input))); $this->_form = $countryForm; break; default: throw new \Jazzee\Exception("{$result->sVerifyLevel} is not a known QAS address verification type.", E_USER_ERROR, 'There was a problem verifying your address. Please try entering it again.'); } break; } return false; }