From cdea489fcbd63a99476fffe5586cbdf2cca57a17 Mon Sep 17 00:00:00 2001 From: Andrew Short Date: Mon, 11 Jun 2012 23:15:18 +1000 Subject: [PATCH] BUGFIX: Catch and display validation errors when adding a page. --- code/controllers/CMSPageAddController.php | 11 ++- .../Includes/CMSPageAddController_Content.ss | 69 +++++++++---------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/code/controllers/CMSPageAddController.php b/code/controllers/CMSPageAddController.php index ebe58020..09fbfb27 100644 --- a/code/controllers/CMSPageAddController.php +++ b/code/controllers/CMSPageAddController.php @@ -118,10 +118,17 @@ class CMSPageAddController extends CMSPageEditController { if(!SiteConfig::current_site_config()->canCreateTopLevel()) return Security::permissionFailure($this); } - + $record = $this->getNewItem("new-$className-$parentID".$suffix, false); if(class_exists('Translatable') && $record->hasExtension('Translatable')) $record->Locale = $data['Locale']; - $record->write(); + + try { + $record->write(); + } catch(ValidationException $ex) { + $form->sessionMessage($ex->getResult()->message(), 'bad'); + return $this->getResponseNegotiator()->respond($this->request); + } + $editController = singleton('CMSPageEditController'); $editController->setCurrentPageID($record->ID); diff --git a/templates/Includes/CMSPageAddController_Content.ss b/templates/Includes/CMSPageAddController_Content.ss index 1683921c..4457072c 100644 --- a/templates/Includes/CMSPageAddController_Content.ss +++ b/templates/Includes/CMSPageAddController_Content.ss @@ -1,37 +1,36 @@ -<% with AddForm %> -
- -
-
-

<% _t('CMSAddPageController.Title','Add page') %>

+
+ <% with AddForm %> + +
+
+

<% _t('CMSAddPageController.Title','Add page') %>

+
-
- -
- - <% if Message %> -

$Message

- <% else %> - - <% end_if %> - -
- <% if Legend %>$Legend<% end_if %> - <% loop Fields %> - $FieldHolder - <% end_loop %> -
-
- -
- <% if Actions %> -
- <% loop Actions %> - $Field - <% end_loop %> + +
+ <% if Message %> +

$Message

+ <% else %> + + <% end_if %> + +
+ <% if Legend %>$Legend<% end_if %> + <% loop Fields %> + $FieldHolder + <% end_loop %> +
- <% end_if %> -
- - -<% end_with %> + +
+ <% if Actions %> +
+ <% loop Actions %> + $Field + <% end_loop %> +
+ <% end_if %> +
+ + <% end_with %> +