Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX: Catch and display validation errors when adding a page.

  • Loading branch information...
commit cdea489fcbd63a99476fffe5586cbdf2cca57a17 1 parent 098d3b6
Andrew Short ajshort authored
11 code/controllers/CMSPageAddController.php
View
@@ -118,10 +118,17 @@ public function doAdd($data, $form) {
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);
69 templates/Includes/CMSPageAddController_Content.ss
View
@@ -1,37 +1,36 @@
-<% with AddForm %>
- <form $FormAttributes data-layout-type="border">
-
- <div class="cms-content-header north">
- <div class="cms-content-header-info">
- <h2><% _t('CMSAddPageController.Title','Add page') %></h2>
+<div class="cms-content center $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
+ <% with AddForm %>
+ <form $FormAttributes data-layout-type="border">
+ <div class="cms-content-header north">
+ <div class="cms-content-header-info">
+ <h2><% _t('CMSAddPageController.Title','Add page') %></h2>
+ </div>
</div>
- </div>
-
- <div class="cms-content-fields center cms-panel-content cms-panel-padded">
-
- <% if Message %>
- <p id="{$FormName}_error" class="message $MessageType">$Message</p>
- <% else %>
- <p id="{$FormName}_error" class="message $MessageType" style="display: none"></p>
- <% end_if %>
-
- <fieldset>
- <% if Legend %><legend>$Legend</legend><% end_if %>
- <% loop Fields %>
- $FieldHolder
- <% end_loop %>
- </fieldset>
- </div>
-
- <div class="cms-content-actions south">
- <% if Actions %>
- <div class="Actions">
- <% loop Actions %>
- $Field
- <% end_loop %>
+
+ <div class="cms-content-fields center cms-panel-content cms-panel-padded">
+ <% if Message %>
+ <p id="{$FormName}_error" class="message $MessageType">$Message</p>
+ <% else %>
+ <p id="{$FormName}_error" class="message $MessageType" style="display: none"></p>
+ <% end_if %>
+
+ <fieldset>
+ <% if Legend %><legend>$Legend</legend><% end_if %>
+ <% loop Fields %>
+ $FieldHolder
+ <% end_loop %>
+ </fieldset>
</div>
- <% end_if %>
- </div>
-
- </form>
-<% end_with %>
+
+ <div class="cms-content-actions south">
+ <% if Actions %>
+ <div class="Actions">
+ <% loop Actions %>
+ $Field
+ <% end_loop %>
+ </div>
+ <% end_if %>
+ </div>
+ </form>
+ <% end_with %>
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.