From 03c480e32e609d9b86ab6a88c688b42d57fee86a Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Mon, 14 Mar 2016 23:45:47 +0100 Subject: [PATCH] Fix error when customized ID is not selected --- create_poll.php | 21 ++++++++++++--------- js/app/create_poll.js | 6 +++--- tpl/create_poll.tpl | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/create_poll.php b/create_poll.php index fefdbe9..5d02b5b 100644 --- a/create_poll.php +++ b/create_poll.php @@ -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,11 +101,13 @@ if ($goToStep2) { $error_on_title = true; } - 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 ($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']) { diff --git a/js/app/create_poll.js b/js/app/create_poll.js index 0ee8bdb..601fd7c 100644 --- a/js/app/create_poll.js +++ b/js/app/create_poll.js @@ -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") diff --git a/tpl/create_poll.tpl b/tpl/create_poll.tpl index e8fba49..aad0e6e 100644 --- a/tpl/create_poll.tpl +++ b/tpl/create_poll.tpl @@ -39,7 +39,7 @@
- +