/** * Validate field * @param string $value * @return string */ public function validate($value) { if (!empty($value) && strstr($value, '://') === FALSE) { $value = 'http://' . $value; } return parent::validate($value); }
public function validate($value) { if (is_array($value) && isset($value['path']) && isset($value['dataURL'])) { $fileName = str_replace('..', '', $value['path']); /* secure relative path */ /* find an unused name */ $fileInfo = pathinfo($fileName); $base = $fileInfo['filename']; $ext = $fileInfo['extension']; $dir = empty($fileInfo['dirname']) ? '' : $fileInfo['dirname'] . '/'; /* $fileInfo['dirname'] in case that filename contains a part of dirname */ $path = PROFILE_PATH . $this->entity->getModule() . '/' . $this->path . '/'; $nbn = 0; while (is_file($path . $fileName)) { $fileName = $dir . $base . '_' . $nbn . '.' . $ext; $nbn++; } if (!is_dir($path . $dir)) { \tools::createDirectory($path . $fileInfo['dirname'] . '/'); } /* decode dataURL */ $cut = explode(',', $value['dataURL']); $dataURL = $cut[1]; $dataURL = base64_decode(str_replace(' ', '+', $dataURL)); /* save and check image */ if (file_put_contents($path . $fileName, $dataURL)) { return $fileName; } else { return FALSE; /* can't write image */ } } else { return parent::validate($value); } }
function validate() { if ($this->isRequired() && $this->get() == 0) { $error['type'] = 'required'; $error['help'] = translate('field_checkbox_must_be_checked'); $this->errors[] = $error; } return parent::validate(); }
function validate() { // check if we need to test if it is a valid email adress : if (isset($this->config['validation']['is_url'])) { if (!$this->isValidUrl($this->get())) { $error['type'] = 'is_url'; $error['help'] = translate('field_is_not_an_url'); $this->errors[] = $error; } } // don't break the validation chain return parent::validate(); }