Exemplo n.º 1
0
 /**
  * 
  * Constructor
  * 
  * @param string $type control type
  * @param array $args params for validate
  */
 public function __construct($type, $args)
 {
     parent::__construct($type, $args);
     //we expect an item with key 'count' and an item with key 'mincount' in $args
     $this->count = isset($args['count']) ? $args['count'] : 0;
     $this->mincount = isset($args['mincount']) ? $args['mincount'] : 0;
 }
Exemplo n.º 2
0
 /**
  * 
  * Constructor
  * 
  * @param string $type control type
  * @param array $args params for validate
  */
 public function __construct($type, $args)
 {
     parent::__construct($type, $args);
     $this->regex = '/^(http|https|ftp)\\:\\/\\/[a-z0-9\\-\\.]+\\.[a-z]{2,3}(:[a-z0-9]*)?\\/?([a-z0-9\\-\\._\\?\\,\'\\/\\\\+&%\\$#\\=~])*$/i';
     //we expect an item with key 'value' in $args
     $this->value = isset($args['value']) ? $args['value'] : "";
 }
Exemplo n.º 3
0
 /**
  * 
  * Constructor
  * 
  * @param string $type control type
  * @param array $args params for validate
  */
 public function __construct($type, $args)
 {
     parent::__construct($type, $args);
     //we expect an item with key 'value' and an item with key 'cvalue' in $args
     $this->value = isset($args['value']) ? $args['value'] : '';
     $this->cvalue = isset($args['cvalue']) ? $args['cvalue'] : '';
 }
Exemplo n.º 4
0
 /**
  * 
  * Constructor
  * 
  * @param string $type control type
  * @param array $args params for validate
  */
 public function __construct($type, $args)
 {
     parent::__construct($type, $args);
     $this->regex = '/^([a-zA-Z0-9_\\.\\-\\+%])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$/';
     //we expect an item with key 'value' in $args
     $this->value = isset($args['value']) ? $args['value'] : "";
 }
Exemplo n.º 5
0
 /**
  * Method to validate values set by post according to business logic
  * Invalid post values can have effects on the disabled state of other fields
  * Therefor we do not validate for required yet!
  */
 protected function validatePostValue()
 {
     //rules for date are: equalTo
     //update $this->field with value from $this->fields
     $this->updateField();
     $valid = true;
     $app = JFactory::getApplication();
     //only to perform when the value is not empty
     if ($this->field->attribute_value != "") {
         //perform equalTo validation
         if (isset($this->field->validate_equalTo) && $this->field->validate_equalTo != '0') {
             $value = $this->field->attribute_value;
             $id = str_replace("#field", "", $this->field->validate_equalTo);
             foreach ($this->fields as $equalToField) {
                 if ($equalToField->id == $id) {
                     if (VisformsValidate::validate('equalto', array('value' => $value, 'cvalue' => $equalToField->attribute_value)) == false) {
                         //invalid value
                         $valid = false;
                         //set error message
                         $app->enqueueMessage(JText::sprintf('COM_VISFORMS_EQUAL_TO_VALIDATION_FAILED', $equalToField->label, $this->field->label));
                         break;
                     }
                 }
             }
         }
         //validate unique field value in database
         $this->validateUniqueValue();
     }
     //at least one validation failed
     if (!$valid) {
         $this->field->isValid = false;
     }
 }
Exemplo n.º 6
0
 /**
  * 
  * Constructor
  * 
  * @param string $type control type
  * @param array $args params for validate
  */
 public function __construct($type, $args)
 {
     parent::__construct($type, $args);
     //we expect an item with key 'value' and an item with key 'regex' in $args
     $this->value = isset($args['value']) ? $args['value'] : "";
     $this->regex = isset($args['regex']) ? $args['regex'] : "";
 }
Exemplo n.º 7
0
 /**
  * Method to validate values set by post according to business logic
  * Invalid post values can have effects on the disabled state of other fields
  * Therefor we do not validate for required yet!
  */
 protected function validatePostValue()
 {
     //rules for selects are: maxcount
     //update $this->field with value from $this->fields
     $this->updateField();
     $app = JFactory::getApplication();
     $valid = true;
     //check that we do not have to many selected values in user input
     if (!isset($this->field->attribute_multiple) || $this->field->attribute_multiple == false) {
         $maxcount = 1;
         $count = 0;
         //get count ouf selected options
         foreach ($this->field->opts as $opt) {
             if (isset($opt['selected']) && $opt['selected'] == true) {
                 $count++;
             }
         }
         if (VisformsValidate::validate('max', array('count' => $count, 'maxcount' => $maxcount)) == false) {
             //invalid value
             $valid = false;
             //set error message
             $app->enqueueMessage(JText::sprintf('COM_VISFORMS_FIELD_MAX_LENGTH_MULTICHECKBOX', $maxcount, $this->field->label));
             //only the last option will be displayed as selected in form
             //set selected to false except for the last selected option,
             $optCount = count($this->field->opts);
             for ($i = 0; $i < $optCount; $i++) {
                 //unselect option
                 if (isset($this->field->opts[$i]['selected']) && $this->field->opts[$i]['selected'] == true && $count != 1) {
                     $this->field->opts[$i]['selected'] = false;
                     $count--;
                 }
                 //perform additional things, which may be necessary because of the wrong amount of selected values, when we reach the last option
                 if ($i == $optCount - 1) {
                     if (isset($this->field->isDisplayChanger) && $this->field->isDisplayChanger == true) {
                         //mend isDisabled property in all depending fields (setIsDisabeld() is recursive)
                         foreach ($this->fields as $child) {
                             //only check for fields that are not $this->field
                             if ($child->id != $this->field->id) {
                                 $this->setIsDisabled($child);
                             }
                         }
                         break;
                     } else {
                         break;
                     }
                 }
             }
         }
     }
     //validate unique field value in database
     $this->validateUniqueValue();
     //at least one validation failed
     if (!$valid) {
         $this->field->isValid = false;
     }
 }
Exemplo n.º 8
0
 public function check()
 {
     $model = new VisformsModelVisdatas();
     $fields = $model->getDatafields();
     $check = true;
     foreach ($fields as $field) {
         $fname = 'F' . $field->id;
         if ($field->typefield == 'date' && isset($this->{$fname}) && $this->{$fname} != "") {
             $formats = explode(';', $field->defaultvalue['f_date_format']);
             $format = $formats[0];
             if (VisformsValidate::validate('date', array('value' => $this->{$fname}, 'format' => $format)) == false) {
                 JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_VISFORMS_DATE_FORMAT_CANNOT_BE_CHANGED', $field->name, $format), 'warning');
                 $check = false;
             }
         }
     }
     return $check;
 }
Exemplo n.º 9
0
 /**
  * 
  * Method to validate user inputs, if not: set field property isValid to false and set error message
  * @param string $inputType user input type (postValue, queryValue)
  */
 protected function validateUserInput($inputType)
 {
     $type = $this->type;
     $value = $this->{$inputType};
     //Empty value is valid
     if ($value == "") {
         return;
     }
     //if a value is set we test it is a valid number (which still may have dots and commas
     if (VisformsValidate::validate($type, array('value' => $value))) {
         return;
     } else {
         //invalid user inputs - set field->isValid to false
         $this->field->isValid = false;
         //set the Error Message
         VisformsMessage::getMessage($this->field->name, $type);
         return;
     }
 }
Exemplo n.º 10
0
 /**
  * 
  * Constructor
  * 
  * @param string $type control type
  * @param array $args params for validate
  */
 public function __construct($type, $args)
 {
     parent::__construct($type, $args);
     $this->regex = '/^-?(?:\\d+|\\d{1,3}(?:,\\d{3})+)?(?:\\.\\d+)?$/';
     $this->value = isset($args['value']) ? $args['value'] : 0;
 }
Exemplo n.º 11
0
 /**
  * Methode to validate if a post value is set in field, if we deal with a post and the field is required and not disabled
  * @return object field
  */
 public function validateRequired()
 {
     if (isset($this->field->dataSource) && $this->field->dataSource == 'post') {
         $app = JFactory::getApplication();
         //check that a value is set if field is required
         if (isset($this->field->attribute_required) && $this->field->attribute_required == true) {
             if (!isset($this->field->isDisabled) || $this->field->isDisabled === false) {
                 if (VisformsValidate::validate('notempty', array('value' => $this->field->attribute_value)) == false) {
                     $this->field->isValid = false;
                     //set error message
                     $app->enqueueMessage(JText::sprintf('COM_VISFORMS_FIELD_REQUIRED', $this->field->label));
                 }
             }
         }
     }
     return $this->field;
 }
Exemplo n.º 12
0
 /**
  * 
  * Method to validate user inputs, if not: set field property isValid to false and set error message
  * @param string $inputType user input type (postValue, queryValue)
  */
 protected function validateUserInput($inputType)
 {
     $type = $this->type;
     $value = $this->{$inputType};
     //Empty value is valid
     if ($value == "") {
         return true;
     }
     //if a value is set we test it has a valid date format
     if (VisformsValidate::validate($type, array('value' => $value, 'format' => $this->field->dateFormatPhp))) {
         return true;
     } else {
         //invalid date format - set field->isValid to false
         $this->field->isValid = false;
         //set the Error Message
         VisformsMessage::getMessage($this->field->name, $type, array('format' => $this->field->dateFormatPhp));
         //we cannot use the value!
         return false;
     }
 }