Esempio n. 1
0
 /**
  * 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);
 }
Esempio n. 2
0
 /**
  * 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);
 }