Merge pull request #40 from tractorcow/pulls/fix-validation

BUG Fix double encoding of validation errors
This commit is contained in:
Christopher Pitt 2015-08-18 08:20:43 +12:00
commit cbd0ec9e00
2 changed files with 4 additions and 32 deletions

View File

@ -555,40 +555,14 @@ JS
/** /**
* Process the form that is submitted through the site * Process the form that is submitted through the site
* *
* {@see UserForm::validate()} for validation step prior to processing
*
* @param array $data * @param array $data
* @param Form $form * @param Form $form
* *
* @return Redirection * @return Redirection
*/ */
public function process($data, $form) { public function process($data, $form) {
Session::set("FormInfo.{$form->FormName()}.data",$data);
Session::clear("FormInfo.{$form->FormName()}.errors");
foreach($this->Fields() as $field) {
$messages[$field->Name] = $field->getErrorMessage()->HTML();
$formField = $field->getFormField();
if($field->Required && $field->DisplayRules()->Count() == 0) {
if(isset($data[$field->Name])) {
$formField->setValue($data[$field->Name]);
}
if(
!isset($data[$field->Name]) ||
!$data[$field->Name] ||
!$formField->validate($form->getValidator())
) {
$form->addErrorMessage($field->Name, $field->getErrorMessage(), 'bad');
}
}
}
if(Session::get("FormInfo.{$form->FormName()}.errors")){
Controller::curr()->redirectBack();
return;
}
$submittedForm = Object::create('SubmittedForm'); $submittedForm = Object::create('SubmittedForm');
$submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0; $submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
$submittedForm->ParentID = $this->ID; $submittedForm->ParentID = $this->ID;
@ -598,9 +572,7 @@ JS
$submittedForm->write(); $submittedForm->write();
} }
$values = array();
$attachments = array(); $attachments = array();
$submittedFields = new ArrayList(); $submittedFields = new ArrayList();
foreach($this->Fields() as $field) { foreach($this->Fields() as $field) {

View File

@ -675,7 +675,7 @@ class EditableFormField extends DataObject {
!$data[$this->Name] || !$data[$this->Name] ||
!$formField->validate($form->getValidator()) !$formField->validate($form->getValidator())
) { ) {
$form->addErrorMessage($this->Name, $this->getErrorMessage(), 'bad'); $form->addErrorMessage($this->Name, $this->getErrorMessage()->HTML(), 'bad', false);
} }
} }