Unverified Commit 71345815 authored by Thomas Citharel's avatar Thomas Citharel
Browse files

Fix ValueMax validation and improve error messages for username format



Closes #295
New translation strings
Check that ValueMax is >= 1
Show details if error in advanced settings
Correctly show error message for ValueMax
Make email field an email one
Make username, email (if smtp of course) and title required html inputs
Signed-off-by: default avatarThomas Citharel <tcit@tcit.fr>
parent 2d069918
......@@ -76,12 +76,14 @@ class InputService {
public function filterMD5($control) {
return filter_var($control, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => MD5_REGEX]]);
}
public function filterInteger($int) {
if (filter_var($int, FILTER_VALIDATE_INT)) {
return $int;
}
return null;
return filter_var($int, FILTER_VALIDATE_INT);
}
public function filterValueMax($int)
{
return $this->filterInteger($int) >= 1;
}
public function filterBoolean($boolean) {
......
......@@ -57,7 +57,7 @@ if ($goToStep2) {
$title = $inputService->filterTitle($_POST['title']);
$use_ValueMax = isset($_POST['use_ValueMax']) ? $inputService->filterBoolean($_POST['use_ValueMax']) : false;
$ValueMax = $use_ValueMax === true ? $inputService->filterInteger($_POST['ValueMax']) : null;
$ValueMax = $use_ValueMax === true ? $inputService->filterValueMax($_POST['ValueMax']) : null;
$use_customized_url = isset($_POST['use_customized_url']) ? $inputService->filterBoolean($_POST['use_customized_url']) : false;
$customized_url = $use_customized_url === true ? $inputService->filterId($_POST['customized_url']) : null;
......@@ -98,10 +98,8 @@ if ($goToStep2) {
$_SESSION['form']->use_password = ($use_password !== null);
$_SESSION['form']->results_publicly_visible = ($results_publicly_visible !== null);
if ($config['use_smtp'] === true) {
if (empty($mail)) {
$error_on_mail = true;
}
if ($config['use_smtp'] === true && empty($mail)) {
$error_on_mail = true;
}
if ($title !== $_POST['title']) {
......@@ -117,11 +115,8 @@ if ($goToStep2) {
}
}
if ($use_ValueMax) {
if ($use_ValueMax === false) {
$error_on_ValueMax = true;
$error_on_customized_url_msg = __('Error', 'Mauvaise valeur');
}
if ($use_ValueMax && $ValueMax === false) {
$error_on_ValueMax = true;
}
if ($name !== $_POST['name']) {
......@@ -234,7 +229,7 @@ if (!empty($_POST[GO_TO_STEP_2])) {
if ($error_on_customized_url) {
$errors['customized_url']['aria'] = 'aria-describeby="customized_url" ';
$errors['customized_url']['class'] = ' has-error';
$errors['customized_url']['msg'] = isset($error_on_customized_url_msg) ? $error_on_customized_url_msg : __('Error', 'Something is wrong with the format');
$errors['customized_url']['msg'] = isset($error_on_customized_url_msg) ? $error_on_customized_url_msg : __('Error', "Something is wrong with the format: customized urls should only consist of alphanumeric characters and hyphens.");
}
if ($error_on_description) {
......@@ -250,7 +245,7 @@ if (!empty($_POST[GO_TO_STEP_2])) {
} elseif ($error_on_name) {
$errors['name']['aria'] = 'aria-describeby="poll_name_error" ';
$errors['name']['class'] = ' has-error';
$errors['name']['msg'] = __('Error', 'Something is wrong with the format');
$errors['name']['msg'] = __('Error', "Something is wrong with the format: name shouldn't have any spaces before or after");
}
if (empty($_POST['mail'])) {
......@@ -276,7 +271,7 @@ if (!empty($_POST[GO_TO_STEP_2])) {
if ($error_on_ValueMax) {
$errors['ValueMax']['aria'] = 'aria-describeby="poll_ValueMax" ';
$errors['ValueMax']['class'] = ' has-error';
$errors['ValueMax']['msg'] = __('Error', 'error on ValueMax');
$errors['ValueMax']['msg'] = __('Error', 'Error on amount of voters limitation : value must be an integer greater than 0');
}
}
......@@ -285,6 +280,7 @@ $useRemoteUser = USE_REMOTE_USER && isset($_SERVER['REMOTE_USER']);
$smarty->assign('title', $title);
$smarty->assign('useRemoteUser', $useRemoteUser);
$smarty->assign('errors', $errors);
$smarty->assign('advanced_errors', $goToStep2 && ($error_on_ValueMax || $error_on_customized_url || $error_on_password || $error_on_password_repeat));
$smarty->assign('use_smtp', $config['use_smtp']);
$smarty->assign('default_to_marldown_editor', $config['markdown_editor_by_default']);
$smarty->assign('goToStep2', GO_TO_STEP_2);
......
......@@ -328,7 +328,7 @@
"All voters can modify any vote": "All voters can modify any vote",
"Customize the URL": "Customize the URL",
"Go to step 2": "الإنتقال إلى الخطوة 2",
"Limit the ammount of voters per option": "Limit the amount of voters per option",
"Limit the amount of voters per option": "Limit the amount of voters per option",
"More informations here:": "المزيد من التفاصيل هنا :",
"Only the poll maker can see the poll's results": "Only the poll maker can see the poll results",
"Optional parameters": "Optional parameters",
......
......@@ -328,7 +328,7 @@
"All voters can modify any vote": "An holl vouezhierien a c'hall kemmañ an holl vouezhioù",
"Customize the URL": "Personelaat an ere",
"Go to step 2": "Mont d'ar bazenn 2",
"Limit the ammount of voters per option": "Limit the amount of voters per option",
"Limit the amount of voters per option": "Limit the amount of voters per option",
"More informations here:": "Titouroù ouzhpenn amañ:",
"Only the poll maker can see the poll's results": "N'eus nemet krouer ar sontadeg a c'hell gwelet an disoc'hoù",
"Optional parameters": "Arventennoù diret",
......
......@@ -328,7 +328,7 @@
"All voters can modify any vote": "Jeder Teilnehmer kann jede abgegebene Wertung ändern",
"Customize the URL": "Link anpassen",
"Go to step 2": "Weiter zum 2. Schritt",
"Limit the ammount of voters per option": "Begrenzung der anzahl der aähler pro option",
"Limit the amount of voters per option": "Begrenzung der anzahl der aähler pro option",
"More informations here:": "DE_Plus d'informations ici :",
"Only the poll maker can see the poll's results": "Einzig der Autor der Abstimmung kann die Ergebnisse einsehen",
"Optional parameters": "Optionale Einstellungen",
......
......@@ -142,7 +142,10 @@
"Poll id already used": "Identifier is already used",
"Something is going wrong...": "Something has gone wrong...",
"Something is wrong with the format": "Something is wrong with the format",
"Something is wrong with the format: customized urls should only consist of alphanumeric characters and hyphens.": "Something is wrong with the format: customized urls should only consist of alphanumeric characters and hyphens.",
"Something is wrong with the format: name shouldn't have any spaces before or after": "Something is wrong with the format: name shouldn't have any spaces before or after",
"The address is not correct! You should enter a valid email address (like r.stallman@outlock.com) in order to receive the link to your poll.": "The address is not correct! You should enter a valid email address (like r.stallman@outlock.com) in order to receive the link to your poll.",
"Error on amount of voters limitation : value must be an integer greater than 0": "Error on amount of voters limitation : value must be an integer greater than 0",
"The column already exists": "The column already exists",
"The name is invalid.": "The name is invalid.",
"The name you've chosen already exist in this poll!": "The name you've chosen already exists in this poll!",
......@@ -328,7 +331,7 @@
"All voters can modify any vote": "All voters can modify any vote",
"Customize the URL": "Customize the URL",
"Go to step 2": "Go to step 2",
"Limit the ammount of voters per option": "Limit the amount of voters per option",
"Limit the amount of voters per option": "Limit the amount of voters per option",
"More informations here:": "More informations here:",
"Only the poll maker can see the poll's results": "Only the poll maker can see the poll results",
"Optional parameters": "Optional parameters",
......
......@@ -328,7 +328,7 @@
"All voters can modify any vote": "Los votos pueden ser modificados por cualquiera",
"Customize the URL": "ES_Personnaliser le lien",
"Go to step 2": "Ir al paso número 2",
"Limit the ammount of voters per option": "Limitar el número de votantes por opción",
"Limit the amount of voters per option": "Limitar el número de votantes por opción",
"More informations here:": "ES_Plus d'informations ici :",
"Only the poll maker can see the poll's results": "Solo el creador de la encuesta puede ver los resultados",
"Optional parameters": "ES_Paramètres optionnels",
......
......@@ -142,7 +142,10 @@
"Poll id already used": "L'identifiant est déjà utilisé",
"Something is going wrong...": "Quelque chose ne va pas...",
"Something is wrong with the format": "Quelque chose ne va pas avec le format",
"Something is wrong with the format: customized urls should only consist of alphanumeric characters and hyphens.": "Quelque chose ne va pas avec le format: les urls personalisées devraient contenir uniquement des caractères alphanumériques et des tirets.",
"Something is wrong with the format: name shouldn't have any spaces before or after": "Quelque chose ne va pas avec le format : le nom ne devrait pas contenir d'espaces avant ou après",
"The address is not correct! You should enter a valid email address (like r.stallman@outlock.com) in order to receive the link to your poll.": "L'adresse saisie n'est pas correcte ! Il faut une adresse électronique valide (par exemple r.stallman@outlock.com) pour recevoir le lien vers le sondage.",
"Error on amount of voters limitation : value must be an integer greater than 0": "Erreur sur le nombre maximum de votants : la valeur doit être un entier supérieur à 0",
"The column already exists": "La colonne existe déjà",
"The name is invalid.": "Le nom n'est pas valide.",
"The name you've chosen already exist in this poll!": "Le nom que vous avez choisi existe déjà !",
......@@ -328,7 +331,7 @@
"All voters can modify any vote": "Tou·te·s les sondé·e·s peuvent modifier tous les votes",
"Customize the URL": "Personnaliser le lien",
"Go to step 2": "Aller à l'étape 2",
"Limit the ammount of voters per option": "limiter le nombre de votants par option",
"Limit the amount of voters per option": "limiter le nombre de votants par option",
"More informations here:": "Plus d'informations ici :",
"Only the poll maker can see the poll's results": "Seul le ou la créateur·rice du sondage peut voir les résultats",
"Optional parameters": "Paramètres facultatifs",
......
......@@ -142,7 +142,10 @@
"Poll id already used": "L'identifiant est déjà utilisé",
"Something is going wrong...": "Quelque chose ne va pas...",
"Something is wrong with the format": "Quelque chose ne va pas avec le format",
"Something is wrong with the format: customized urls should only consist of alphanumeric characters and hyphens.": "Quelque chose ne va pas avec le format : les urls personalisées devraient contenir uniquement des caractères alphanumériques et des tirets.",
"Something is wrong with the format: name shouldn't have any spaces before or after": "Quelque chose ne va pas avec le format : le nom ne devrait pas contenir d'espaces avant ou après",
"The address is not correct! You should enter a valid email address (like r.stallman@outlock.com) in order to receive the link to your poll.": "L'adresse saisie n'est pas correcte ! Il faut une adresse électronique valide (par exemple r.stallman@outlock.com) pour recevoir le lien vers le sondage.",
"Error on amount of voters limitation : value must be an integer greater than 0": "Erreur sur le nombre maximum de votants : la valeur doit être un entier supérieur à 0",
"The column already exists": "La colonne existe déjà",
"The name is invalid.": "Le nom n'est pas valide.",
"The name you've chosen already exist in this poll!": "Le nom que vous avez choisi existe déjà !",
......@@ -328,7 +331,7 @@
"All voters can modify any vote": "Tou·te·s les sondé·e·s peuvent modifier tous les votes",
"Customize the URL": "Personnaliser le lien",
"Go to step 2": "Aller à l'étape 2",
"Limit the ammount of voters per option": "limiter le nombre de votants par option",
"Limit the amount of voters per option": "limiter le nombre de votants par option",
"More informations here:": "Plus d'informations ici :",
"Only the poll maker can see the poll's results": "Seul le ou la créateur·rice du sondage peut voir les résultats",
"Optional parameters": "Paramètres facultatifs",
......
......@@ -328,7 +328,7 @@
"All voters can modify any vote": "Tutti i votanti possono cambiare tutti i voti",
"Customize the URL": "Personalizzare il link",
"Go to step 2": "Andare al punto 2",
"Limit the ammount of voters per option": "Limitare la quantità di elettori per opzione",
"Limit the amount of voters per option": "Limitare la quantità di elettori per opzione",
"More informations here:": "IT_Plus d'informations ici :",
"Only the poll maker can see the poll's results": "Solo il creatore sondaggio possono vedere i risultati",
"Optional parameters": "Parametri opzionali",
......
......@@ -328,7 +328,7 @@
"All voters can modify any vote": "Alle stemmers kunnen elke stem aanpassen",
"Customize the URL": "Link verpersoonlijken",
"Go to step 2": "Ga naar stap 2",
"Limit the ammount of voters per option": "Limit the amount of voters per option",
"Limit the amount of voters per option": "Limit the amount of voters per option",
"More informations here:": "More informations here:",
"Only the poll maker can see the poll's results": "Alleen degene die de poll aangemaakt heeft kan de resultaten zien",
"Optional parameters": "Optionele parameters",
......
......@@ -328,7 +328,7 @@
"All voters can modify any vote": "Totes los votants pòdon modificar sos vòtes",
"Customize the URL": "Personalizar lo ligam",
"Go to step 2": "Anar a l’etapa 2",
"Limit the ammount of voters per option": "Limitar lo nombre de votants per opcion",
"Limit the amount of voters per option": "Limitar lo nombre de votants per opcion",
"More informations here:": "Mai d’informacion aquí :",
"Only the poll maker can see the poll's results": "Solament lo creator del sondatge pòt veire los resultats",
"Optional parameters": "Paramètres opcionals",
......
......@@ -28,7 +28,7 @@
{if $useRemoteUser}
<input type="hidden" name="name" value="{$form->admin_name}" />{$form->admin_name}
{else}
<input id="yourname" type="text" name="name" class="form-control" {$errors['name']['aria']} value="{$poll_name|html}" />
<input id="yourname" type="text" required name="name" class="form-control" {$errors['name']['aria']} value="{$poll_name|html}" />
{/if}
</div>
</div>
......@@ -51,7 +51,7 @@
{if $useRemoteUser}
<input type="hidden" name="mail" value="{$form->admin_mail}">{$form->admin_mail}
{else}
<input id="email" type="text" name="mail" class="form-control" {$errors['email']['aria']} value="{$poll_mail|html}" />
<input id="email" required type="email" name="mail" class="form-control" {$errors['email']['aria']} value="{$poll_mail|html}" />
{/if}
</div>
</div>
......@@ -69,7 +69,7 @@
<label for="poll_title" class="col-sm-4 control-label">{__('Step 1', 'Poll title')} *</label>
<div class="col-sm-8">
<input id="poll_title" type="text" name="title" class="form-control" {$errors['title']['aria']}
<input id="poll_title" type="text" name="title" class="form-control" required {$errors['title']['aria']}
value="{$poll_title|html}"/>
</div>
</div>
......@@ -111,7 +111,7 @@
<span class="lead visible-xs-inline">
<i class="glyphicon glyphicon-cog" aria-hidden="true"></i>
</span>
<a class="optionnal-parameters collapsed lead" role="button" data-toggle="collapse" href="#optionnal" aria-expanded="false" aria-controls="optionnal">
<a class="optionnal-parameters {if !$advanced_errors}collapsed{/if} lead" role="button" data-toggle="collapse" href="#optionnal" aria-expanded="{if $advanced_errors}false{else}true{/if}" aria-controls="optionnal">
{__('Step 1', "Optional parameters")}
<i class="caret" aria-hidden="true"></i>
<i class="caret caret-up" aria-hidden="true"></i>
......@@ -121,32 +121,32 @@
<div class="clearfix"></div>
<div class="collapse" id="optionnal">
<div class="collapse{if $advanced_errors} in{/if}" id="optionnal" {if $advanced_errors}aria-expanded="true"{/if}>
{* Poll identifier *}
<div class="form-group {$errors['customized_url']['class']}">
{* Value MAX *}
<div class="form-group">
<div class="form-group {$errors['ValueMax']['class']}">
<label for="use_valueMax" class="col-sm-4 control-label">
{__('Step 1', 'Value Max')}<br/>
</label>
<div class="col-sm-8">
<div class="checkbox">
<label>
<input id="use_ValueMax" name="use_ValueMax" type="checkbox" >
{__('Step 1', "Limit the ammount of voters per option")}
<input id="use_ValueMax" name="use_ValueMax" type="checkbox" {if $use_ValueMax}checked{/if}>
{__('Step 1', "Limit the amount of voters per option")}
</label>
</div>
</div>
</div>
<div class="form-group">
<div id="ValueMax"{if !$use_ValueMax} class="hidden"{/if}>
<div class="form-group {$errors['ValueMax']['class']}">
<div id="ValueMax" {if !$use_ValueMax}class="hidden"{/if}>
<div class="col-sm-offset-4 col-sm-8">
<label>
<input id="ValueMax" type="number" min= "0" name="ValueMax">
<input id="ValueMax" type="number" min="0" name="ValueMax" value="{$ValueMax|html}" {$errors['ValueMax']['aria']}>
{__('Step 1', "ValueMax instructions")}
</label>
......@@ -155,6 +155,14 @@
</div>
</div>
{if !empty($errors['ValueMax']['msg'])}
<div class="alert alert-danger">
<p id="poll_customized_url_error">
{$errors['ValueMax']['msg']}
</p>
</div>
{/if}
{* Poll identifier *}
<div class="form-group {$errors['customized_url']['class']}">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment