From 692e3582039b3c399b016cc932d8735e64a6b298 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 7 Dec 2020 16:24:36 +0100 Subject: [PATCH] Add required and type=email to forms This gives the browser more information to do validation (though #359 must be fixed to actually make this effective) and allows HTMLForm to validate these fields automatically (so this allows removing most `$form->validateXXXField()` calls). --- system/datatypes/festival.php | 20 ++++++-------------- system/datatypes/mailinglist.php | 19 +++++-------------- system/datatypes/peer_reviewed_article.php | 18 +++--------------- system/datatypes/text.php | 9 +++------ 4 files changed, 17 insertions(+), 49 deletions(-) diff --git a/system/datatypes/festival.php b/system/datatypes/festival.php index b73db0a1..336cc8ef 100644 --- a/system/datatypes/festival.php +++ b/system/datatypes/festival.php @@ -294,7 +294,7 @@ protected function createSettingsForm(array $values=[]) { - +
EOF; @@ -337,8 +337,6 @@ protected function settingsSaveAction(HyphaRequest $request) { // create form $form = $this->createSettingsForm($request->getPostData()); - - $form->validateRequiredField(self::FIELD_NAME_TITLE); $form->validate(); // process form if it was posted @@ -373,12 +371,12 @@ private function createSignupForm(array $values = []) { - + - + @@ -439,9 +437,6 @@ protected function signupAction(HyphaRequest $request) { // create form $form = $this->createSignupForm($request->getPostData()); - $form->validateRequiredField(self::FIELD_NAME_NAME); - $form->validateRequiredField(self::FIELD_NAME_EMAIL); - $form->validateEmailField(self::FIELD_NAME_EMAIL); $form->validateMoneyField(self::FIELD_NAME_AMOUNT); $form->validate(); @@ -636,12 +631,12 @@ private function createContributionForm(array $values = []) {
*
*
- + - + @@ -664,7 +659,7 @@ private function createContributionForm(array $values = []) { -
*
*
+ : EOF; @@ -916,8 +907,8 @@ protected function createEditForm(array $values = []) { $html = << - - + +
@@ -956,10 +947,10 @@ protected function createEditForm(array $values = []) { protected function createMailingForm(array $values = []) { $html = << - +
- +
EOF; diff --git a/system/datatypes/peer_reviewed_article.php b/system/datatypes/peer_reviewed_article.php index ed02f217..370a86cd 100644 --- a/system/datatypes/peer_reviewed_article.php +++ b/system/datatypes/peer_reviewed_article.php @@ -829,12 +829,6 @@ protected function discussionAction(HyphaRequest $request) { // create form to start a discussion $form = $this->createCommentForm($type, $request->getPostData()); - if (!$review && !isUser()) { - $form->validateRequiredField(self::FIELD_NAME_DISCUSSION_COMMENTER_NAME . $dataFieldSuffix); - $form->validateRequiredField(self::FIELD_NAME_DISCUSSION_COMMENTER_EMAIL . $dataFieldSuffix); - $form->validateEmailField(self::FIELD_NAME_DISCUSSION_COMMENTER_EMAIL . $dataFieldSuffix); - } - $form->validateRequiredField(self::FIELD_NAME_DISCUSSION_COMMENT . $dataFieldSuffix); $form->validate(); // process form if it was posted @@ -927,12 +921,6 @@ protected function discussionCommentAction(HyphaRequest $request) { // create form to comment on a discussion $form = $this->createCommentForm($type, $request->getPostData(), $discussion); - if (!$review && !isUser()) { - $form->validateRequiredField(self::FIELD_NAME_DISCUSSION_COMMENTER_NAME . $dataFieldSuffix); - $form->validateRequiredField(self::FIELD_NAME_DISCUSSION_COMMENTER_EMAIL . $dataFieldSuffix); - $form->validateEmailField(self::FIELD_NAME_DISCUSSION_COMMENTER_EMAIL . $dataFieldSuffix); - } - $form->validateRequiredField(self::FIELD_NAME_DISCUSSION_COMMENT . $dataFieldSuffix); $form->validate(); // process form if it was posted @@ -1747,7 +1735,7 @@ protected function createCommentForm($type, array $values = [], HyphaDomElement $html = <<
- +
EOF; @@ -1771,10 +1759,10 @@ protected function createCommentForm($type, array $values = [], HyphaDomElement // only non-users need to enter their name $html .= << -
[[un-anonymous]]
+
[[un-anonymous]]
- +
[[info-button-subscribe]] diff --git a/system/datatypes/text.php b/system/datatypes/text.php index 659ae650..f2b7d30e 100644 --- a/system/datatypes/text.php +++ b/system/datatypes/text.php @@ -94,7 +94,7 @@ protected function createEditForm(array $values = []) { $html = << - +
@@ -155,7 +155,6 @@ protected function editAction(HyphaRequest $request) { $form = $this->createEditForm($request->getPostData()); // validate - $form->validateRequiredField(self::FIELD_NAME_PAGE_NAME); $form->validate(); // process form if it was posted @@ -220,9 +219,7 @@ protected function translateAction(HyphaRequest $request) { $form = $this->createTranslationForm($request->getPostData()); // validate - $form->validateRequiredField(self::FIELD_NAME_PAGE_NAME); // TODO: validate that the language is a valid one - $form->validateRequiredField(self::FIELD_NAME_LANGUAGE); $form->validate(); // process form if it was posted @@ -282,11 +279,11 @@ protected function createTranslationForm(array $values = []) { $html = << - +
- +
EOF;