1779 Posts in 582 Topics by 556 members
| Go to End | ||
| Author | Topic: | 2940 Views |
-
Re: Custom validation of the form fields on the server side

14 March 2013 at 3:44am
Benwu, did you check out the netefxvalidator module ?
-
Re: Custom validation of the form fields on the server side

14 March 2013 at 4:05am Last edited: 14 March 2013 4:05am
netefxvalidator is quite handy.
however, i think the best solution is to validate dats just before the write method. if fails, do a redirectBack. It's a shame the form got clear out. Hope wilr got time to find out? not sure how data are passed from one page to another.
-
Re: Custom validation of the form fields on the server side

3 April 2013 at 7:09am Last edited: 3 April 2013 7:10am
I've always thought there had to be an easy way to do this - took a lot of frustrating digging to work out a solution today but finally found one thanks to a hint in an SSBits post.
//The function that handles our form submission
function sendForm($data, $form) {
//Custom validation
if ($data['FieldName'] == 0) { //Some logical test
//Add error message to field
$form->addErrorMessage('FieldName','Something went wrong!','required');
//Set form data from submitted values
Session::set("FormInfo.".$form->FormName().".data", $data);
//Return back to form
return $this->redirectBack();
}
... -
Re: Custom validation of the form fields on the server side

3 April 2013 at 9:44am
Just something I stumbled upon today in 2.4: instead of using RequiredFields you can use the CustomRequiredFields class that for every fiield lets you add an array, where you can add functionality to check if the value for that field is correct, and the error message to show if it isn't.
The message will be displayed next to the field, just like the regular required field message. I used that today in a form with a double e-mailfield, where the values in both fields should be equal. Works like a charm! Unfortunately, unless I'm mistaken, it doesn't seem to have made it into 3.0...
| 2940 Views | ||
| Go to Top |



