[html-formfu] Suppressing error message output?
Matthias Dietrich
perl at rainboxx.de
Wed May 6 11:13:22 GMT 2009
Hi,
hm, I see I have forgotten something :).
> Hmm, not easy - I'd normally suggest looking at t/examples/ for custom
> rendering, but the render_field() and render_label() methods require
> TT.
>
> I'd suggest inspecting the field errors to build your error message.
> Something like this (as a very rough example):
>
> my $error_message = '';
> for my $field ( @{ $form->get_fields } ) {
> my @errors = @{ $field->get_errors({ forced => 1 });
> next if !@errors;
> $error_message .= sprintf '<p>field %s has errors</p><ul>', (
> $field->label || $field->name );
> for my $error (@errors) {
> $error_message .= sprintf '<li>%s</li>', $error->message;
> }
> $error_message .= '</ul>';
> }
I already have the collected error messages, although your way seems
to be much better and I will adapt that - thanks!
> To get it displayed at the top of the form:
>
> # use _xml() variant as our message contains xhtml tags
> $form->form_error_message_xml( $error_message );
Ok, I will try that. Good point! As I'm really new to FormFu I would
have placed the message manually in front of the form :(.
> And clear the errors attached to the fields:
>
> $form->clear_errors;
>
> And to get the top error message to display now that the form has no
> errors:
>
> $form->force_error_message( 1 );
To clear the errors was the only way I found to suppress the error
message output in front of the labels. But I guess that also
suppresses modification of the field classes so that I'm not able to
mark the labels red by CSS, right?
In my opinion it's a much better user experience to have the occurred
errors in front of the form instead letting the user search through
the whole form to find the errors. But I also want to have an
indicator near the fields saying that this field needs corrections
(like a star oder red colored label). Clearing the errors will also
prevent indicating the fields.
Thanks for helping,
Matthias
--
rainboxx Matthias Dietrich
Freier Software Engineer
rainboxx | Tel.: +49 (0) 151 / 50 60 78 64
Tölzer Str. 19 | Mail: matt at rainboxx.de
70372 Stuttgart | WWW : http://www.rainboxx.de
XING: https://www.xing.com/profile/Matthias_Dietrich18
GULP: http://www.gulp.de/profil/rainboxx.html
NEU: Auf Perl spezialisierte Projektvermittlung!
Bald mehr auf http://www.perl-experten.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 194 bytes
Desc: Signierter Teil der Nachricht
Url : http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20090506/7ead497f/PGP.pgp
More information about the HTML-FormFu
mailing list