Benwu, did you check out the netefxvalidator module ?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
- Previous 10 entries
- 1
- Page 22(current)
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.
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();
}
...
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...
- Previous 10 entries
- 1
- Page 22(current)