Skip to content
This repository
Browse code

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

  • Loading branch information...
commit cdea489fcbd63a99476fffe5586cbdf2cca57a17 1 parent 098d3b6
Andrew Short authored June 11, 2012
11  code/controllers/CMSPageAddController.php
@@ -118,10 +118,17 @@ public function doAdd($data, $form) {
118 118
 			if(!SiteConfig::current_site_config()->canCreateTopLevel())
119 119
 				return Security::permissionFailure($this);
120 120
 		}
121  
-		
  121
+
122 122
 		$record = $this->getNewItem("new-$className-$parentID".$suffix, false);
123 123
 		if(class_exists('Translatable') && $record->hasExtension('Translatable')) $record->Locale = $data['Locale'];
124  
-		$record->write();
  124
+
  125
+		try {
  126
+			$record->write();
  127
+		} catch(ValidationException $ex) {
  128
+			$form->sessionMessage($ex->getResult()->message(), 'bad');
  129
+			return $this->getResponseNegotiator()->respond($this->request);
  130
+		}
  131
+
125 132
 		$editController = singleton('CMSPageEditController');
126 133
 		$editController->setCurrentPageID($record->ID);
127 134
 
69  templates/Includes/CMSPageAddController_Content.ss
... ...
@@ -1,37 +1,36 @@
1  
-<% with AddForm %>
2  
-	<form $FormAttributes data-layout-type="border">
3  
-
4  
-		<div class="cms-content-header north">
5  
-			<div class="cms-content-header-info">
6  
-				<h2><% _t('CMSAddPageController.Title','Add page') %></h2>
  1
+<div class="cms-content center $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
  2
+	<% with AddForm %>
  3
+		<form $FormAttributes data-layout-type="border">
  4
+			<div class="cms-content-header north">
  5
+				<div class="cms-content-header-info">
  6
+					<h2><% _t('CMSAddPageController.Title','Add page') %></h2>
  7
+				</div>
7 8
 			</div>
8  
-		</div>
9  
-
10  
-		<div class="cms-content-fields center cms-panel-content cms-panel-padded">
11  
-
12  
-			<% if Message %>
13  
-			<p id="{$FormName}_error" class="message $MessageType">$Message</p>
14  
-			<% else %>
15  
-			<p id="{$FormName}_error" class="message $MessageType" style="display: none"></p>
16  
-			<% end_if %>
17  
-
18  
-			<fieldset>
19  
-				<% if Legend %><legend>$Legend</legend><% end_if %> 
20  
-				<% loop Fields %>
21  
-					$FieldHolder
22  
-				<% end_loop %>
23  
-			</fieldset>
24  
-		</div>
25  
-
26  
-		<div class="cms-content-actions south">
27  
-			<% if Actions %>
28  
-			<div class="Actions">
29  
-				<% loop Actions %>
30  
-					$Field
31  
-				<% end_loop %>
  9
+	
  10
+			<div class="cms-content-fields center cms-panel-content cms-panel-padded">
  11
+				<% if Message %>
  12
+				<p id="{$FormName}_error" class="message $MessageType">$Message</p>
  13
+				<% else %>
  14
+				<p id="{$FormName}_error" class="message $MessageType" style="display: none"></p>
  15
+				<% end_if %>
  16
+	
  17
+				<fieldset>
  18
+					<% if Legend %><legend>$Legend</legend><% end_if %> 
  19
+					<% loop Fields %>
  20
+						$FieldHolder
  21
+					<% end_loop %>
  22
+				</fieldset>
32 23
 			</div>
33  
-			<% end_if %>
34  
-		</div>
35  
-
36  
-	</form>
37  
-<% end_with %>
  24
+	
  25
+			<div class="cms-content-actions south">
  26
+				<% if Actions %>
  27
+				<div class="Actions">
  28
+					<% loop Actions %>
  29
+						$Field
  30
+					<% end_loop %>
  31
+				</div>
  32
+				<% end_if %>
  33
+			</div>
  34
+		</form>
  35
+	<% end_with %>
  36
+</div>

0 notes on commit cdea489

Please sign in to comment.
Something went wrong with that request. Please try again.