public function validate(\Foundation\Form\Input $input) { if ($input->get($this->e->getName()) != $input->get($this->ruleSet)) { $this->addError('Does not match ' . $this->e->getField()->getForm()->getElementByname($this->ruleSet)->getLabel()); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if (strlen($input->get($this->e->getName())) < $this->ruleSet) { $this->addError('Input is too small. Your input is: ' . ($this->ruleSet - strlen($input->get($this->e->getName()))) . ' characters smaller than the minimum size of ' . $this->ruleSet); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if (strlen($input->get($this->e->getName())) > $this->ruleSet) { $this->addError('Input is too large. Your input is: ' . (strlen($input->get($this->e->getName())) - $this->ruleSet) . ' characters bigger than the maximum size of ' . $this->ruleSet); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if ($input->get($this->e->getName()) < $this->ruleSet[0] or $input->get($this->e->getName()) > $this->ruleSet[1]) { $this->addError("Value must be between {$this->ruleSet[0]} and {$this->ruleSet[1]}"); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if (strtotime($input->get($this->e->getName())) <= strtotime($input->get($this->ruleSet))) { $this->addError('Must be after date in ' . $this->e->getField()->getForm()->getElementByName($this->ruleSet)->getLabel()); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { //work with an array so checkboxes and multi select can be validated in the same way if (!\is_array($input->get($this->e->getName()))) { $checked = array($input->get($this->e->getName())); } else { $checked = $input->get($this->e->getName()); } foreach ($this->e->getItems() as $item) { if (!in_array($item->getValue(), $checked)) { $this->addError('You did not check ' . $item->getLabel()); } } return true; }
public function validate(\Foundation\Form\Input $input) { //work with an array so checkboxes and multi select can be validated in the same way if (!\is_array($input->get($this->e->getName()))) { $arr = array($input->get($this->e->getName())); } else { $arr = $input->get($this->e->getName()); } foreach ($arr as $value) { if (!$this->e->inList($value)) { $this->addError('That is not a valid option.'); return false; } } return true; }
public function validate(\Foundation\Form\Input $input) { if (null === json_decode($input->get($this->e->getName()))) { $error = ''; switch (json_last_error()) { case JSON_ERROR_DEPTH: $error = 'Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: $error = 'Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: $error = 'Unexpected control character found'; break; case JSON_ERROR_SYNTAX: $error = 'Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: $error = 'Malformed UTF-8 characters, possibly incorrectly encoded'; break; default: $error = 'Unknown error'; break; } $this->addError('Error Decoding JSON: ' . $error); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if (!\preg_match($this->ruleSet, $input->get($this->e->getName()))) { $this->addError($this->errorMessage); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if (@preg_match($input->get($this->e->getName()), null) === false) { $this->addError('Not a valid regular expression'); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if ($input->get($this->e->getName()) != $this->ruleSet) { $this->addError('You must type ' . $this->ruleSet . ' in this box.'); return false; } return true; }
public function validateNull(\Foundation\Form\Input $input) { if (is_null($input->get($this->e->getName()))) { $this->addError('This field is required and you left it blank'); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if (strtotime($input->get($this->e->getName())) > strtotime($this->ruleSet)) { $this->addError('Date must be before ' . $this->ruleSet); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if (!strtotime($input->get($this->e->getName()))) { $this->addError('Not a valid date'); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { if (!\filter_var($input->get($this->e->getName()), FILTER_VALIDATE_INT)) { $this->addError('An integer is required for this field'); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { $fileArr = $input->get($this->e->getName()); if ($fileArr['size'] > $this->ruleSet) { $this->addError('File is too large. Your file is: ' . \Foundation\Utility::convertBytesToString($fileArr['size'] - $this->ruleSet) . ' bigger than the maximum size of ' . \Foundation\Utility::convertBytesToString($this->ruleSet, 0)); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { $method = $this->ruleSet['method']; $object = $this->ruleSet['object']; if (!$object->{$method}($input->get($this->e->getName()))) { $this->addError($this->ruleSet['errorMessage']); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { $fileArr = $input->get($this->e->getName()); $contents = file_get_contents($fileArr['tmp_name']); if (strpos($contents, '/Encrypt')) { $this->addError("This PDF file appears to be password protected or encrypted and " . "cannot be accepted by our system."); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { //only keep the digits $number = preg_replace("#[^0-9]#", '', $input->get($this->e->getName())); $length = \strlen($number); if ($length < 10 or $length > 13) { $this->addError('Invalid Phone Number'); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { $fileArr = $input->get($this->e->getName()); $retcode = cl_scanfile($fileArr['tmp_name'], $virusname); if ($retcode == CL_VIRUS) { unlink($fileArr['tmp_name']); $this->addError('Virus Detection Error: ' . cl_pretcode($retcode) . " {$virusname}."); return false; } return true; }
public function validate(\Foundation\Form\Input $input) { $value = $input->get($this->e->getName()); //get the last @ sign $lastAtSign = \strrpos($value, '@'); if ($lastAtSign === false) { $this->addError(self::ERROR); return false; } $localPart = \substr($value, 0, $lastAtSign); $domainPart = \substr($value, $lastAtSign + 1); //check the lengths of the parts first becuase it is fast if (\strlen($localPart) < 1 or \strlen($localPart) > 64 or \strlen($domainPart) < 1 or \strlen($domainPart) > 255) { $this->addError(self::ERROR); return false; } //then check the content of the local part if (!\preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', \str_replace("\\\\", "", $localPart))) { //The local part must be quoted if (!\preg_match('/^"(\\\\"|[^"])+"$/', \str_replace("\\\\", "", $localPart))) { $this->addError(self::ERROR); return false; } } //dot isn't the first or last charecter if ($localPart[0] == '.' or $localPart[\strlen($localPart) - 1] == '.') { $this->addError(self::ERROR); return false; } //no two consecutive dots if (\preg_match('/\\.\\./', $localPart)) { $this->addError(self::ERROR); return false; } if (!\preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domainPart)) { $this->addError(self::ERROR); return false; } if (\preg_match('/\\.\\./', $domainPart)) { $this->addError(self::ERROR); return false; } if ($this->ruleSet) { if (!(\checkdnsrr($domainPart, "MX") or \checkdnsrr($domainPart, "A"))) { $this->addError(self::ERROR); return false; } } return true; }
public function validate(\Foundation\Form\Input $input) { $value = $input->get($this->e->getName()); $number = \filter_var($value, FILTER_SANITIZE_NUMBER_INT); if (!$this->passesLuhnCheck($number)) { $this->addError(self::ERROR_INVALID); return false; } $type = $this->discoverCardType($value); if (!in_array($type, $this->ruleSet)) { $this->addError(self::ERROR_NOT_ACCEPTED); return false; } return true; }
/** * Transform input into a valid date string * @see Foundation\Form\Element.AbstractElement::processInput() */ public function processInput(\Foundation\Form\Input $input) { if (!is_null($input->get($this->getName() . '-month')) and !is_null($input->get($this->getName() . '-year'))) { //create a date using the first day of the month $input->set($this->getName(), $input->get($this->getName() . '-year') . '-' . $input->get($this->getName() . '-month') . '-1'); } elseif (!is_null($input->get($this->getName()))) { $arr = explode(' ', $input->get($this->getName())); $input->set($this->getName(), "{$arr[1]}-{$arr[0]}-1"); } return parent::processInput($input); }
/** * Fileinput has soem work done pre validation * @param FormInput $input * @return boolean */ protected function validate(\Foundation\Form\Input $input) { $fileArr = $input->get($this->getName()); //if no file was updaed if ($fileArr['size'] == 0 and $fileArr['name'] === '') { $input->set($this->getName(), null); //set the file upload to null } else { //look for upload errors if ($fileArr['error'] != \UPLOAD_ERR_OK) { switch ($fileArr['error']) { case \UPLOAD_ERR_INI_SIZE: case \UPLOAD_ERR_FORM_SIZE: $text = 'Your file is greater than the maximum allowed size of ' . \Foundation\Utility::convertBytesToString($this->getMaxSize()); break; case \UPLOAD_ERR_PARTIAL: $text = 'Your file upload was stopped before it completed. ' . 'This is probably a temporary problem with your connection to our server. ' . 'Please try again.'; break; case UPLOAD_ERR_NO_FILE: $text = 'No file was uploaded'; break; //the rest of the errors are configuration errors and throw exceptions //the rest of the errors are configuration errors and throw exceptions case UPLOAD_ERR_NO_TMP_DIR: throw new \Foundation\Exception('Unable to upload file: no temporary directory was found.', \E_USER_ERROR, 'The server encountered an error uploading your file. Please try again.'); break; case UPLOAD_ERR_CANT_WRITE: throw new \Foundation\Exception('Unable to upload file: could not write to disk.', E_USER_ERROR, 'The server encountered an error uploading your file. Please try again.'); break; case \UPLOAD_ERR_EXTENSION: throw new \Foundation\Exception('Unable to upload file: A PHP extension stopped the file upload. ' . 'PHP does not provide a way to ascertain which extension caused the file upload to stop.', E_USER_ERROR, 'The server encountered an error uploading your file. Please try again.'); break; default: $text = 'There was an error uploading your file. Please try again.'; } //get rid of the input because there isn't realy a file $input->set($this->getName(), null); //write any error messages to the validationSet $this->addMessage($text); return false; } } return parent::validate($input); }
public function validate(\Foundation\Form\Input $input) { $validMimeTypes = array('application/pdf', 'application/pdf; charset=binary', 'application/x-pdf', 'application/acrobat', 'applications/vnd.pdf', 'text/pdf', 'text/x-pdf'); $fileArr = $input->get($this->e->getName()); //obviously easily changed but check the extension $arr = explode('.', $fileArr['name']); $extension = array_pop($arr); if (strtolower($extension) != 'pdf') { $this->addError("This is a file has the extension .{$extension} .pdf is required."); return false; } $finfo = finfo_open(FILEINFO_MIME); $mimetype = finfo_file($finfo, $fileArr['tmp_name']); finfo_close($finfo); if (!\in_array($mimetype, $validMimeTypes)) { $this->addError("This is a file of type {$mimetype} which is not a valid PDF."); return false; } return true; }
/** * Validate that the minimum answers have been submitted and that there are no duplicates * @param \Foundation\Form\Input $input */ public function validate(\Foundation\Form\Input $input) { $existingChoices = array(); //we put each choice in here so we don't get duplicates $values = $input->get($this->e->getName()); for ($i = 0; $i < $this->e->getTotalItems(); $i++) { $value = $values[$i]; if (!empty($value)) { if (in_array($value, $existingChoices)) { $this->e->addMessage('You have selected the same item twice'); return false; } else { $existingChoices[] = $value; } } } if (count($existingChoices) < $this->e->getRequiredItems()) { $this->e->addMessage('You must rank at least ' . $this->e->getRequiredItems() . ' items'); return false; } return true; }
/** * Use ValidateNull becuase the actual input for the element is not what is important * @param \Foundation\Form\Input $input */ public function validateNull(\Foundation\Form\Input $input) { //discard empty submissions if ($input->get('recaptcha_challenge_field') == null or \strlen($input->get('recaptcha_challenge_field')) == 0 or $input->get('recaptcha_response_field') == null or \strlen($input->get('recaptcha_response_field')) == 0) { $this->e->errorString = 'incorrect-captcha-sol'; $this->addError(''); return false; } $response = $this->httpPost(self::VERIFY_SERVER, "/recaptcha/api/verify", array('privatekey' => $this->ruleSet, 'remoteip' => $_SERVER['REMOTE_ADDR'], 'challenge' => $input->get('recaptcha_challenge_field'), 'response' => $input->get('recaptcha_response_field'))); $answers = explode("\n", $response[1]); if (trim($answers[0]) == 'false') { $this->e->errorString = $answers[1]; $this->addError(''); return false; } return true; }
/** * Contact anet and attempt to refund the payment * @see ApplyPaymentInterface::refundPayment() */ public function refundPayment(\Jazzee\Entity\Payment $payment, \Foundation\Form\Input $input) { $aim = new \AuthorizeNetAIM($this->_paymentType->getVar('gatewayId'), $this->_paymentType->getVar('gatewayKey')); $aim->setSandBox($this->_paymentType->getVar('testAccount')); //test accounts get sent to the sandbox $aim->test_request = $this->_controller->getConfig()->getStatus() == 'PRODUCTION' ? 0 : 1; $aim->zip = $input->get('zip'); $response = $aim->credit($payment->getVar('transactionId'), $payment->getAmount(), $input->get('cardNumber')); if ($response->approved) { $payment->refunded(); $payment->setVar('refundedReason', $input->get('refundedReason')); return true; } else { return "Unable to submit refund for transaction #{$payment->getVar('transactionId')} authorize.net said: " . $response->getMessageText(); } return false; }
/** * Update the LOR * @param \Foundation\Form\Input $input * @param \Jazzee\Entity\Answer $answer */ public function updateLorAnswer(\Foundation\Form\Input $input, \Jazzee\Entity\Answer $answer) { foreach ($answer->getElementAnswers() as $ea) { $answer->getElementAnswers()->removeElement($ea); $this->_controller->getEntityManager()->remove($ea); } foreach ($answer->getPage()->getElements() as $element) { $element->getJazzeeElement()->setController($this->_controller); foreach ($element->getJazzeeElement()->getElementAnswers($input->get('el' . $element->getId())) as $elementAnswer) { $answer->addElementAnswer($elementAnswer); } } $this->getForm()->applyDefaultValues(); $this->getForm()->setAction($this->_controller->getActionPath()); $this->_controller->getEntityManager()->persist($answer); }
/** * Contact anet and attempt to refund the payment * @see ApplyPaymentInterface::refundPayment() */ public function refundPayment(\Jazzee\Entity\Payment $payment, \Foundation\Form\Input $input) { $client = new \SoapClient(self::CASHNET_WSDL); $parameters = array('OperatorID' => $this->_paymentType->getVar('operatorId'), 'Password' => $this->_paymentType->getVar('operatorPassword'), 'VirtualDirectory' => $this->_controller->getConfig()->getStatus() == 'PRODUCTION' ? self::CASHNET_VIRTUALDIRECTORY : self::CASHNET_TEST_VIRTUALDIRECTORY, 'TransactionNo' => $input->get('transactionId')); $results = $client->CASHNetSOAPRequestInquiry(array('inquiryParams' => $parameters)); $xml = new \SimpleXMLElement($results->CASHNetSOAPRequestInquiryResult); if ($xml->result != 0) { return "Unable to get refund transaction details from cashnet for payment: {$payment->getId()}, transaction: {$input->get('transactionId')} for applicant {$payment->getAnswer()->getApplicant()->getId()}. Cashnet said: {$xml->respmessage}"; } if ($xml->transactions[0]->transaction->txno == $input->get('transactionId')) { $payment->refunded(); $payment->setVar('refundAmount', $xml->transactions[0]->transaction->totalamount); $payment->setVar('refundTransactionId', $xml->transactions[0]->transaction->txno); $payment->setVar('refundedReason', $input->get('refundedReason')); return true; } else { throw new \Jazzee\Exception("Transaction details differ between cashnet and payment: {$payment->getId()} for applicant {$payment->getAnswer()->getApplicant()->getId()}."); } return true; }