External form and validation

Permalink 2 users found helpful
I'm building a custom form (Done with External Form block), and i'm able to parse and validate the fields, the problem is that Concrete doesn't seem to set the fields with errors with any class, so i'm unable to highlight the errors to the user.
Is there any way to do this?

View Replies: View Best Answer
mnakalay replied on at Permalink Reply
C5 has an error helper that you can use to implemrnt error checking yourself.
doterobcn replied on at Permalink Reply
Thanks for your answer mnakalay, that's actually what i'm using, but i don't know how to get exact elements that didn't validate.
Benji replied on at Permalink Best Answer Reply
Yeah, while c5 preserves data entered into fields on POST, it doesn't add error classes to form elements or even give field names in the error helper output, unfortunately. But it's not too hard to add this in yourself to your custom controller and view. It's just a matter of going the extra step to have two validation helpers -- one for the string to display to the user and one to store field names for you to exploit in your view and add error classes appropriately. Something like this in your controller:

$val_msg = Loader::helper('validation/form');
$val_name = Loader::helper('validation/form');
$val_msg->addRequired('fname', 'Please provide your first name');
$val_name->addRequired('fname', 'fname');

Then if there are errors, you can iterate through the output of $val_name in your view to see which elements to add an error class to, either by PHP or javascript.

It's far from elegant, but it works.

doterobcn replied on at Permalink Reply
Thanks Benji, i ended up doing something similar (Not as elegant as your code).
Gotta change it for yours!! :)