本文整理汇总了PHP中field::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP field::validate方法的具体用法?PHP field::validate怎么用?PHP field::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field
的用法示例。
在下文中一共展示了field::validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validate field
* @param string $value
* @return string
*/
public function validate($value)
{
if (!empty($value) && strstr($value, '://') === FALSE) {
$value = 'http://' . $value;
}
return parent::validate($value);
}
示例2: validate
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);
}
}
示例3: validate
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();
}
示例4: 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();
}