Fix error when customized ID is not selected

This commit is contained in:
Olivier PEREZ 2016-03-14 23:45:47 +01:00
parent 783affb73a
commit 03c480e32e
3 changed files with 16 additions and 13 deletions

View File

@ -56,17 +56,18 @@ if (isset($_GET['type']) && $_GET['type'] == 'date' ||
$goToStep2 = filter_input(INPUT_POST, GO_TO_STEP_2, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^(date|classic)$/']]);
if ($goToStep2) {
$title = $inputService->filterTitle($_POST['title']);
$id = $inputService->filterId($_POST['id']);
$customizeId = $inputService->filterBoolean($_POST['customize_id']);
$id = $customizeId == true ? $inputService->filterId($_POST['id']) : null;
$name = $inputService->filterName($_POST['name']);
$mail = $inputService->filterMail($_POST['mail']);
$mail = $config['use_smtp'] == true ? $inputService->filterMail($_POST['mail']) : null;
$description = $inputService->filterDescription($_POST['description']);
$editable = $inputService->filterEditable($_POST['editable']);
$receiveNewVotes = isset($_POST['receiveNewVotes']) ? $inputService->filterBoolean($_POST['receiveNewVotes']) : false;
$receiveNewComments = isset($_POST['receiveNewComments']) ? $inputService->filterBoolean($_POST['receiveNewComments']) : false;
$hidden = isset($_POST['hidden']) ? $inputService->filterBoolean($_POST['hidden']) : false;
$use_password = filter_input(INPUT_POST, 'use_password', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_REGEX]]);
$password = isset($_POST['password'])?$_POST['password']:null;
$password_repeat = isset($_POST['password_repeat'])?$_POST['password_repeat']:null;
$password = isset($_POST['password']) ? $_POST['password'] : null;
$password_repeat = isset($_POST['password_repeat']) ? $_POST['password_repeat'] : null;
$results_publicly_visible = filter_input(INPUT_POST, 'results_publicly_visible', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_REGEX]]);
// On initialise également les autres variables
@ -100,12 +101,14 @@ if ($goToStep2) {
$error_on_title = true;
}
if ($customizeId) {
if ($id === false) {
$error_on_id = true;
} else if ($pollRepository->existsById($id)) {
$error_on_id = true;
$error_on_id_msg = __('Error', 'Poll id already used');
}
}
if ($name !== $_POST['name']) {
$error_on_name = true;

View File

@ -37,15 +37,15 @@ $(document).ready(function () {
* Enable/Disable custom id options
*/
var $pollId = $("#poll_id");
var $customId = $("#custom_id");
var $customizeId = $("#customize_id");
// Init checkbox + input
if (($pollId.val() || $pollId.attr('value') || "").length > 0) {
$customId.attr('checked', 'checked');
$customizeId.attr('checked', 'checked');
$pollId.removeAttr("disabled");
}
// Listen for checkbox changes
$customId.change(function () {
$customizeId.change(function () {
if ($(this).prop("checked")) {
$pollId
.removeAttr("disabled")

View File

@ -39,7 +39,7 @@
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon">
<input id="custom_id" type="checkbox"/>
<input id="customize_id" name="customize_id" type="checkbox"/>
</span>
<input id="poll_id" type="text" name="id" class="form-control" {$errors['id']['aria']}
value="{$poll_id}" aria-describedBy="pollIdDesc" disabled="disabled" maxlength="64"