Skip Menu |

This queue is for tickets about the HTML-FillInForm CPAN distribution.

Report information
The Basics
Id: 6342
Status: resolved
Priority: 0/
Queue: HTML-FillInForm

People
Owner: Nobody in particular
Requestors: trevor.schellhorn-perl [...] marketingtips.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Add 'disable_fields' method
The patch that I have attached adds a 'disable_fields' option to the module. This allows someone to mark fields that they want to be disabled when the form is displayed. Being that we use HTML::FillInForm to pre-fill in forms that get displayed to the user, it will allow the developer to disable certain fields depending on data in their application.
diff -Nru HTML-FillInForm-1.04-orig/lib/HTML/FillInForm.pm HTML-FillInForm-1.04/lib/HTML/FillInForm.pm --- HTML-FillInForm-1.04-orig/lib/HTML/FillInForm.pm 2004-03-08 08:15:51.000000000 -0800 +++ HTML-FillInForm-1.04/lib/HTML/FillInForm.pm 2004-05-18 03:07:38.000000000 -0700 @@ -38,6 +38,11 @@ ? @{ $option{ignore_fields} } : $option{ignore_fields} if exists( $option{ignore_fields} ); $self->{ignore_fields} = \%ignore_fields; + my %disable_fields; + %disable_fields = map { $_ => 1 } ( ref $option{'disable_fields'} eq 'ARRAY' ) + ? @{ $option{disable_fields} } : $option{ignore_fields} if exists( $option{disable_fields} ); + $self->{disable_fields} = \%disable_fields; + if (my $fdat = $option{fdat}){ # Copy the structure to prevent side-effects. my %copy; @@ -120,6 +125,13 @@ $self->{output} .= '>'; delete $self->{option_no_value}; } + + # Check if we need to disable this field + $attr->{disable} = 1 + if exists $attr->{'name'} and + exists $self->{disable_fields}{ $attr->{'name'} } and + $self->{disable_fields}{ $attr->{'name'} } and + not ( exists $attr->{disable} and $attr->{disable} ); if ($tagname eq 'input'){ my $value = exists $attr->{'name'} ? $self->_get_param($attr->{'name'}) : undef; # force hidden fields to have a value @@ -413,6 +425,12 @@ fobject => $q, ignore_fields => ['prev','next']); +To disable the form from being edited, use the C<disable_fields> options: + + $output = $fif->fill(scalarref => \$html, + fobject => $q, + disable_fields => [ 'uid', 'gid' ]); + Note that this module does not clear fields if you set the value to undef. It will clear fields if you set the value to an empty array or an empty string. For example: diff -Nru HTML-FillInForm-1.04-orig/t/19_disable_fields.t HTML-FillInForm-1.04/t/19_disable_fields.t --- HTML-FillInForm-1.04-orig/t/19_disable_fields.t 1969-12-31 16:00:00.000000000 -0800 +++ HTML-FillInForm-1.04/t/19_disable_fields.t 2004-05-18 03:20:15.000000000 -0700 @@ -0,0 +1,28 @@ +#!/usr/local/bin/perl + +# contributed by Trevor Schellhorn + +use strict; +use warnings FATAL => 'all'; + +use Test::More tests => 3; + +use_ok('HTML::FillInForm'); + +my $html = qq[ +<form> +<input type="text" name="one" value="not disturbed"> +<input type="text" name="two" value="not disturbed"> +</form> +]; + +my $result = HTML::FillInForm->new->fill( + scalarref => \$html, + fdat => { + two => "new val 2", + }, + disable_fields => [qw(two)], + ); + +ok($result =~ /not disturbed.+one/,'don\'t disable 1'); +ok($result =~ /new val 2.+two.+disable="1"/,'disable 2');
From: trevor.schellhorn-perl [...] marketingtips.com
[guest - Tue May 18 06:31:11 2004]: Show quoted text
> The patch that I have attached adds a 'disable_fields' option to the > module. This allows someone to mark fields that they want to be > disabled when the form is displayed. > > Being that we use HTML::FillInForm to pre-fill in forms that get > displayed to the user, it will allow the developer to disable certain > fields depending on data in their application.
There is an error in the patch. The line that sets the 'disable' to 1 should actually set 'disabled' to 1.
[guest - Wed May 19 00:31:40 2004]: Show quoted text
> [guest - Tue May 18 06:31:11 2004]: >
> > The patch that I have attached adds a 'disable_fields' option to the > > module. This allows someone to mark fields that they want to be > > disabled when the form is displayed. > > > > Being that we use HTML::FillInForm to pre-fill in forms that get > > displayed to the user, it will allow the developer to disable certain > > fields depending on data in their application.
> > There is an error in the patch. The line that sets the 'disable' to 1 > should actually set 'disabled' to 1.
And you will also have to update the test cases to reflect the change. Sorry about the typo in the patch.