Skip to content

Commit

Permalink
API Escape form validation messages (SS-2013-008)
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Sep 24, 2013
1 parent 114fb59 commit c243418
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 12 additions & 8 deletions forms/Form.php
Expand Up @@ -65,7 +65,7 @@ class Form extends RequestHandler {
protected $validator;

protected $formMethod = "post";

protected static $current_action;

/**
Expand Down Expand Up @@ -144,6 +144,10 @@ class Form extends RequestHandler {
*/
protected $attributes = array();

public static $casting = array(
'Message' => 'Text'
);

/**
* Create a new form, with the given fields an action buttons.
*
Expand Down Expand Up @@ -203,7 +207,7 @@ public function __construct($controller, $name, FieldList $fields, FieldList $ac
'GET ' => 'httpSubmission',
'HEAD ' => 'httpSubmission',
);

/**
* Set up current form errors in session to
* the current form if appropriate.
Expand Down Expand Up @@ -239,7 +243,7 @@ public function setupFormErrors() {
* if the form is valid.
*/
public function httpSubmission($request) {
$vars = $request->requestVars();
$vars = $request->requestVars();
if(isset($funcName)) {
Form::set_current_action($funcName);
}
Expand Down Expand Up @@ -281,7 +285,7 @@ public function httpSubmission($request) {
if(isset($funcName)) {
$this->setButtonClicked($funcName);
}

// Permission checks (first on controller, then falling back to form)
if(
// Ensure that the action is actually a button or method on the form,
Expand Down Expand Up @@ -355,8 +359,8 @@ public function httpSubmission($request) {
}
return $this->controller->redirectBack();
}
}
}

// First, try a handler method on the controller (has been checked for allowed_actions above already)
if($this->controller->hasMethod($funcName)) {
return $this->controller->$funcName($vars, $this, $request);
Expand Down Expand Up @@ -439,7 +443,7 @@ public function getRedirectToFormOnValidationError() {
}

/**
* Add an error message to a field on this form. It will be saved into the session
* Add a plain text error message to a field on this form. It will be saved into the session
* and used the next time this form is displayed.
*/
public function addErrorMessage($fieldName, $message, $messageType) {
Expand Down Expand Up @@ -865,7 +869,7 @@ public function setFormMethod($method) {
$this->formMethod = strtolower($method);
return $this;
}

/**
* Return the form's action attribute.
* This is build by adding an executeForm get variable to the parent controller's Link() value
Expand Down
4 changes: 4 additions & 0 deletions forms/FormField.php
Expand Up @@ -93,6 +93,10 @@ class FormField extends RequestHandler {
*/
protected $attributes = array();

public static $casting = array(
'Message' => 'Text'
);

/**
* Takes a fieldname and converts camelcase to spaced
* words. Also resolves combined fieldnames with dot syntax
Expand Down

0 comments on commit c243418

Please sign in to comment.