mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
BUGFIX Added validation (for non javascript submits)
This commit is contained in:
parent
fed25ad45b
commit
a7a3dcb945
@ -324,14 +324,10 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
* @return Array
|
* @return Array
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
if($content = $this->Content) {
|
if($this->Content && $form = $this->Form()) {
|
||||||
$hasLocation = stristr($content, '$UserDefinedForm');
|
$hasLocation = stristr($this->Content, '$UserDefinedForm');
|
||||||
|
|
||||||
if($hasLocation) {
|
if($hasLocation) {
|
||||||
$replace = ($form = $this->Form()) ? $form->forTemplate() : "";
|
$content = str_ireplace('$UserDefinedForm', $form->forTemplate(), $this->Content);
|
||||||
|
|
||||||
$content = str_ireplace('$UserDefinedForm', $replace, $content);
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'Content' => DBField::create('HTMLText', $content),
|
'Content' => DBField::create('HTMLText', $content),
|
||||||
'Form' => ""
|
'Form' => ""
|
||||||
@ -353,7 +349,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
*/
|
*/
|
||||||
function Form() {
|
function Form() {
|
||||||
$fields = $this->getFormFields();
|
$fields = $this->getFormFields();
|
||||||
if(!$fields || !$fields->exists()) return false;
|
if(!$fields) return false;
|
||||||
|
|
||||||
$actions = $this->getFormActions();
|
$actions = $this->getFormActions();
|
||||||
|
|
||||||
@ -365,6 +361,10 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
|
|
||||||
$form = new Form($this, "Form", $fields, $actions, $required);
|
$form = new Form($this, "Form", $fields, $actions, $required);
|
||||||
|
|
||||||
|
$data = Session::get("FormInfo.{$form->FormName()}.data");
|
||||||
|
|
||||||
|
if(is_array($data)) $form->loadDataFrom($data);
|
||||||
|
|
||||||
$this->extend('updateForm', $form);
|
$this->extend('updateForm', $form);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
@ -642,6 +642,29 @@ JS
|
|||||||
* @return Redirection
|
* @return Redirection
|
||||||
*/
|
*/
|
||||||
function process($data, $form) {
|
function process($data, $form) {
|
||||||
|
|
||||||
|
if($this->Fields()) {
|
||||||
|
Session::set("FormInfo.{$form->FormName()}.data",$data);
|
||||||
|
Session::clear("FormInfo.{$form->FormName()}.errors");
|
||||||
|
foreach($this->Fields() as $field) {
|
||||||
|
$messages[$field->Name] = $field->getErrorMessage()->HTML();
|
||||||
|
|
||||||
|
if($field->Required){
|
||||||
|
if( !isset($data[$field->Name]) ||
|
||||||
|
!$data[$field->Name] ||
|
||||||
|
!$field->getFormField()->validate($this->validator)
|
||||||
|
){
|
||||||
|
$form->addErrorMessage($field->Name,$field->getErrorMessage()->HTML(),'bad');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Session::get("FormInfo.{$form->FormName()}.errors")){
|
||||||
|
Director::redirectBack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$submittedForm = Object::create('SubmittedForm');
|
$submittedForm = Object::create('SubmittedForm');
|
||||||
$submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
|
$submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
|
||||||
@ -758,6 +781,9 @@ JS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Session::clear("FormInfo.{$form->FormName()}.errors");
|
||||||
|
Session::clear("FormInfo.{$form->FormName()}.data");
|
||||||
|
|
||||||
$referrer = (isset($data['Referrer'])) ? '?referrer=' . urlencode($data['Referrer']) : "";
|
$referrer = (isset($data['Referrer'])) ? '?referrer=' . urlencode($data['Referrer']) : "";
|
||||||
|
|
||||||
return Director::redirect($this->Link() . 'finished' . $referrer);
|
return Director::redirect($this->Link() . 'finished' . $referrer);
|
||||||
|
Loading…
Reference in New Issue
Block a user