Skip Menu |

This queue is for tickets about the CGI-FormBuilder CPAN distribution.

Report information
The Basics
Id: 56076
Status: rejected
Priority: 0/
Queue: CGI-FormBuilder

People
Owner: Nobody in particular
Requestors: brian@massassi.com (no email address)
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.0501
Fixed in: (no value)



Subject: Upon submission, stylesheet forms lose fb_required class
Using the stylesheet => 1 option AND javascript => 0 option on a form with some required fields, leave one of the required fields blank and submit the form. Since javascript is off, it will let you submit the form w/out filling in the field. Server-side validation detects that the field is empty and marks it as "invalid field." During this process, some logic happens that decides which css class to apply to the label. If there is any invalidity, it marks it fb_invalid and moves on, skipping any other checks, like if the field is marked required. So a field can be marked "fb_invalid" OR "fb_required" but never both. This is a bug, because a field can be both required and invalid. The module should apply two css classes, fb_required AND fb_invalid in this case. I have attached a patch that implements this. I also tried to duplicate the existing behavior for non-stylesheet forms. Also, I realize that in both cases, the fields are bolded. However, using CSS I am applying other styles to fb_required which aren't present on fb_invalid.
Subject: mypatch.patch
diff -u -r fb1\FormBuilder\Template\Builtin.pm fb\FormBuilder\Template\Builtin.pm --- fb1\FormBuilder\Template\Builtin.pm Mon Mar 29 12:58:10 2010 +++ fb\FormBuilder\Template\Builtin.pm Mon Mar 29 12:56:51 2010 @@ -172,14 +172,26 @@ my $cl = $form->class($form->labelname); my $row = ' ' . $form->td(id => $form->idname("_$field", $form->labelname), class => $cl) . $font; + + my @tags; + if ($field->invalid) { - $row .= $form->invalid_tag($field->label); - } elsif ($field->required && ! $field->static) { - $row .= $form->required_tag($field->label); - } else { + push @tags, 'invalid'; + } + + if ($field->required && ! $field->static) { + push @tags, 'required'; + } + + if(@tags) { + $row .= $form->add_tags($field->label, @tags); + } + else { $row .= $field->label; } + $row .= $fcls . htmltag('/td'); + push @html, $row; # tag plus optional errors and/or comments diff -u -r fb1\FormBuilder.pm fb\FormBuilder.pm --- fb1\FormBuilder.pm Mon Mar 29 12:58:10 2010 +++ fb\FormBuilder.pm Mon Mar 29 12:56:51 2010 @@ -1173,6 +1173,27 @@ return wantarray ? @tags : join $label, @tags; } +sub add_tags { + my ($self, $label, @raw_tags) = @_; + + my @tags; + + if($self->{'stylesheet'}) { + my $tags = join(' ', map { "fb_$_" } @raw_tags); + + push @tags, (qq(<span class="$tags">), '</span>'); + } + else { + foreach my $tag (@raw_tags) { + my $method = "${tag}_tag"; + + push @tags, $self->$method($label); + } + } + + return wantarray ? @tags : join $label, @tags; +} + sub cgi_param { my $self = shift; $self->{params}->param(@_);
I appreciate the patch attempt and bug report. However, this causes several other tests to fail. You can run tests by "./runtests". Also, put further issues here: http://github.com/formbuilder/formbuilder