public static function check(FormChecker_Field &$oField, $params) { $fields = array(clone $oField); if (is_array($params)) { foreach ($params as $idx => $fieldName) { $tmpField = $oField->getForm()->getField($fieldName); if (!is_null($tmpField)) { $fields[] = clone $tmpField; } } } else { $tmpField = $oField->getForm()->getField($params); if (!is_null($tmpField)) { $fields[] = clone $tmpField; } } // on a cloner les objets afin de ne pas lancer d'erreur lors de la phase qui suit $rv = false; foreach ($fields as $idx => $tmpField) { if (FormChecker_Helper_RequiredValue::check($tmpField, null)) { $rv = true; } } if ($rv) { return true; } else { $fieldNames = ''; foreach ($fields as $idx => &$tmpField) { $fieldNames .= '"' . $tmpField->getLabel() . '",'; } $fieldNames = substr($fieldNames, 0, strlen($fieldNames) - 1); return $oField->raiseError(sprintf('Veuillez remplir au moins un des champs %s', $fieldNames)); } }
public static function check(FormChecker_Field &$oField, $params) { $source = $oField->getForm()->getField($params['source']); if (strcmp($source->getValue(), $oField->getValue()) == $params['sign']) { return $oField->raiseError($params['error']); } 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) { $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; }
public static function check(FormChecker_Field &$oField, $params) { $source = $oField->getForm()->getField($params['source']); $cmp_sign = 0; $source = (int) $source->getValue(); $field = (int) $oField->getValue(); if ($source < $field) { $cmp_sign = -1; } elseif ($source > $field) { $cmp_sign = 1; } if ($cmp_sign !== $params['sign']) { return $oField->raiseError($params['error']); } 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; }