public static function check(FormChecker_Field &$oField, $params) { if (is_null($oField->getValue()) && !$oField->isRequired()) { return true; } if (!preg_match($params['pattern'], $oField->getValue())) { return $oField->raiseError(sprintf($params['error'], $oField->getLabel())); } return true; }
public static function check(FormChecker_Field &$oField, $params) { $value = $oField->getValue(); if (!isset($value['value'])) { return $oField->raiseError('Wrong data structure for upload field'); } $newValue = $value['value']; $oldValue = isset($value['old']) ? $value['old'] : null; // Si on a une ancienne valeur et que rien de nouveau n'a été soumis, on s'arrête là if (!is_null($oldValue) && UPLOAD_ERR_NO_FILE & $newValue['error']) { return true; } // Il y a une nouvelle valeur > on vérifie le type mime si nécessaire if (!is_null($newValue['tmp_name']) && UPLOAD_ERR_OK == $newValue['error']) { if (!is_null($params) && '*' != $params) { // On a spécifié des types mimes autorisés $allowedTypes = explode(';', $params); if (is_null($newValue['type'])) { return $oField->raiseError(sprintf('Le type du fichier pour "%s" n\'a pu être déterminé', $oField->getLabel())); } elseif (!in_array($newValue['type'], $allowedTypes)) { return $oField->raiseError(sprintf('[%s] Ce type de fichier n\'est pas autorisé : %s', $oField->getLabel(), $params)); } } return true; } if (UPLOAD_ERR_NO_FILE & $newValue['error']) { return !$oField->isRequired() ? true : $oField->raiseError(sprintf('Veuillez remplir le champ "%s"', $oField->getLabel())); } // Si on est pas encore sortie de la méthode c'est qu'il y a eu un soucis // on revérifie la valeur de $newValue[ 'error' ] if ((UPLOAD_ERR_INI_SIZE | UPLOAD_ERR_FORM_SIZE) & $newValue['error']) { $maxSize = $oField->getForm()->getContext()->getParam('MAX_FILE_SIZE'); if (is_null($maxSize)) { $maxSize = ini_get('upload_max_filesize'); } elseif (is_numeric($maxSize)) { $maxSize .= ' octets'; } return $oField->raiseError(sprintf('Le fichier "%s" est trop volumineux - limite %s', $oField->getLabel(), $maxSize)); } elseif (UPLOAD_ERR_PARTIAL & $newValue['error']) { return $oField->raiseError(sprintf('Le fichier "%s" n\'a pas été entièrement téléchargé', $oField->getLabel())); } return false; }
public static function check(FormChecker_Field &$oField, $params) { if (!is_array($params)) { return $oField->raiseError('Les clés possibles doivent être fournies via un tableau associatif'); } if (is_null($oField->getValue()) && !$oField->isRequired()) { return true; } if (!array_key_exists($oField->getValue(), $params)) { return $oField->raiseError(sprintf('La clé "%s" n\'est pas permise pour le champ "%s"', $oField->getValue(), $oField->getLabel())); } return true; }
public static function check(FormChecker_Field &$oField, $params) { if (!is_array($params) || !array_key_exists('master', $params)) { return $oField->raiseError(sprintf('"%s": RequiredDependency est mal configuré', $oField->getLabel())); } $master_field =& $oField->getForm()->getField($params['master']); if (is_null($master_field)) { return $oField->raiseError(sprintf('Le champ "%s" n\'est pas défini pour ce formulaire', $params['master'])); } $master_needed_value = array_key_exists('value', $params) ? $params['value'] : null; $rv = !is_null($master_needed_value) ? $master_field->getValue() == $master_needed_value : !is_null($master_field->getValue()); return $rv ? FormChecker_Helper_RequiredValue::check($oField, null) : true; }
public static function check(FormChecker_Field &$oField, $params) { if (is_array($params) || !isset($params['value'])) { return $oField->raiseError('La valeur attendue doit être scalaire'); } if (is_null($oField->getValue()) && !$oField->isRequired()) { return true; } if ($oField->getValue() != $params['value']) { $err_msg = isset($params['error']) ? $params['error'] : sprintf('La valeur du champ "%s" n\'est pas valide', $oField->getLabel()); return $oField->raiseError($err_msg); } return true; }
public static function check(FormChecker_Field &$oField, $params) { $value = $oField->getValue(); if (is_array($value)) { $rv = self::checkArrayNonEmpty($value); } else { $rv = mb_strlen($value) > 0; } if (!$rv) { if (isset($params['error'])) { return $oField->raiseError($params['error']); } else { return $oField->raiseError(sprintf('Veuillez remplir le champ "%s"', $oField->getLabel())); } } return true; }
public static function check(FormChecker_Field &$oField, $params) { $fields = array(); if (is_array($params)) { foreach ($params as $idx => $fieldName) { $tmpField = $oField->getForm()->getField($fieldName); if (!is_null($tmpField)) { $fields[] =& $tmpField; } } } else { $tmpField = $oField->getForm()->getField($params); if (!is_null($tmpField)) { $fields[] =& $tmpField; } } $rv = true; foreach ($fields as $idx => &$tmpField) { if ($oField->getValue() != $tmpField->getValue()) { $rv = false; } } return !$rv ? $oField->raiseError(sprintf('Le champ "%s" ne correspond pas', $oField->getLabel())) : true; }