Better error management on extrafailed input

This commit is contained in:
fhenry 2013-04-02 14:12:21 +02:00
parent e93b6141e1
commit 735e107a51
6 changed files with 81 additions and 3 deletions

View File

@ -80,6 +80,33 @@ if ($action == 'add')
$mesg[]=$langs->trans("ErrorNoValueForRadioType");
$action = 'create';
}
if (((GETPOST('type')=='radio') || (GETPOST('type')=='checkbox') || (GETPOST('type')=='radio')) && GETPOST('param'))
{
// Construct array for parameter (value of select list)
$parameters = GETPOST('param');
$parameters_array = explode("\r\n",$parameters);
foreach($parameters_array as $param_ligne)
{
if (!empty($param_ligne)) {
if (preg_match_all('/,/',$param_ligne,$matches))
{
if (count($matches[0])>1) {
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne);
$action = 'create';
}
}
else
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne);
$action = 'create';
}
}
}
}
if (! $error)
{
@ -152,6 +179,54 @@ if ($action == 'update')
$mesg[]=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint);
$action = 'edit';
}
if (GETPOST('type')=='select' && !GETPOST('param'))
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForSelectType");
$action = 'edit';
}
if (GETPOST('type')=='checkbox' && !GETPOST('param'))
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForCheckBoxType");
$action = 'edit';
}
if (GETPOST('type')=='radio' && !GETPOST('param'))
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForRadioType");
$action = 'edit';
}
if (((GETPOST('type')=='radio') || (GETPOST('type')=='checkbox') || (GETPOST('type')=='radio')) && GETPOST('param'))
{
// Construct array for parameter (value of select list)
$parameters = GETPOST('param');
$parameters_array = explode("\r\n",$parameters);
foreach($parameters_array as $param_ligne)
{
if (!empty($param_ligne)) {
if (preg_match_all('/,/',$param_ligne,$matches))
{
if (count($matches[0])>1) {
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne);
$action = 'edit';
}
}
else
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorBadFormatValueList",$param_ligne);
$action = 'edit';
}
}
}
}
if (! $error)
{

View File

@ -55,7 +55,7 @@ $required=$extrafields->attribute_required[$attrname];
$pos=$extrafields->attribute_pos[$attrname];
$param=$extrafields->attribute_param[$attrname];
if($type == 'select' && is_array($param))
if((($type == 'select') || ($type == 'checkbox') ||(($type == 'radio'))) && is_array($param))
{
$param_chain = '';
foreach ($param['options'] as $key => $value)
@ -80,7 +80,7 @@ if($type == 'select' && is_array($param))
</td></tr>
<!-- Value (for select list / radio) -->
<?php
if($type == 'select')
if(($type == 'select') || ($type == 'checkbox') ||(($type == 'radio')))
{
?>
<tr id="value_choice">

View File

@ -61,6 +61,7 @@ ErrorSizeTooLongForVarcharType=Size too long for string type (%s chars maximum)
ErrorNoValueForSelectType=Please fill value for select list
ErrorNoValueForCheckBoxType=Please fill value for checkbox list
ErrorNoValueForRadioType=Please fill value for radio list
ErrorBadFormatValueList=The list value cannot have more than one come : <u>%s</u>, but need at least one: llave,valores
ErrorFieldCanNotContainSpecialCharacters=Field <b>%s</b> must not contains special characters.
ErrorNoAccountancyModuleLoaded=No accountancy module activated
ErrorExportDuplicateProfil=This profil name already exists for this export set.

View File

@ -62,6 +62,7 @@ ErrorSizeTooLongForVarcharType=Longitud del campo demasiado largo para el tipo c
ErrorNoValueForSelectType=Los valores de la lista deben ser indicados
ErrorNoValueForCheckBoxType=Los valores de la lista deben ser indicados
ErrorNoValueForRadioType=Los valores de la lista deben ser indicados
ErrorBadFormatValueList=Los valores de la lista no peudo contener mas de una coma : <u>%s</u>, pero necessita una: llave,valores
ErrorFieldCanNotContainSpecialCharacters=El campo <b>%s</b> no debe contener carácteres especiales
ErrorNoAccountancyModuleLoaded=Módulo de contabilidad no activado
ErrorExportDuplicateProfil=El nombre del perfil ya existe para este lote de exportación

View File

@ -355,7 +355,7 @@ ExtrafieldPrice = Prix
ExtrafieldMail = Email
ExtrafieldSelect = Liste de sélection
ExtrafieldSeparator = Séparateur de champ
ExtrafieldCheckBox=Case a cochée
ExtrafieldCheckBox=Case à cocher
ExtrafieldRadio=Case d'option
ExtrafieldParamHelp=La liste doit être de la forme clef,valeur<br><br> par exemple : <br>1,valeur1<br>2,valeur2<br>3,valeur3<br>...
LibraryToBuildPDF=Bibliothèque utilisée pour la génération des PDF

View File

@ -62,6 +62,7 @@ ErrorSizeTooLongForVarcharType=Longueur de champ trop longue pour le type chaine
ErrorNoValueForSelectType=Les valeurs de la liste de selection doivent être renseignées
ErrorNoValueForCheckBoxType=Les valeurs de la liste de case a cochées doivent être renseignées
ErrorNoValueForRadioType=Les valeurs de la liste d'options doivent être renseignées
ErrorBadFormatValueList=Les valeurs de la liste ne peuvent pas contenir plus d'une virgule : <b>%s</b>, mais doivent en avoir au moins une: clef,valeur
ErrorFieldCanNotContainSpecialCharacters=Le champ <b>%s</b> ne peut contenir de caractères spéciaux.
ErrorNoAccountancyModuleLoaded=Aucun module de comptabilité activé
ErrorExportDuplicateProfil=Ce nom de profil existe déjà pour ce lot d'export.