File Coverage

blib/lib/HTML/FormRemove.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package HTML::FormRemove;
2             # -*- Perl -*- Tue May 21 13:01:01 CDT 2002
3             ###############################################################################
4             # Written by Tim Skirvin
5             # Copyright 2000-2002, Tim Skirvin and UIUC Board of Trustees. Redistribution
6             # terms are below.
7             ###############################################################################
8 1     1   663 use vars qw( $VERSION );
  1         2  
  1         67  
9             $VERSION = "0.3a";
10              
11             =head1 NAME
12              
13             HTML::FormRemove - remove form tags from HTML
14              
15             =head1 SYNOPSIS
16              
17             my $html =
18             "
";
19             use HTML::FormRemove
20             print RemoveFormValues($html);
21              
22             =head1 DESCRIPTION
23              
24             HTML::FormRemove is a module that removes form tags from HTML, while
25             otherwise leaving the HTML intact. This allows for forms to be converted
26             into something printable and usable.
27              
28              
29             =cut
30              
31 1     1   5 use strict;
  1         2  
  1         30  
32 1     1   1683 use HTML::Form;
  0            
  0            
33              
34             use Exporter;
35             use vars qw( @EXPORT @EXPORT_OK @ISA );
36             @ISA = "Exporter";
37             @EXPORT = qw( RemoveFormValues );
38              
39             # Untaint $0; this may not be the best idea in the world, but it's
40             # necessary if we're in taint mode
41             if ($0 =~ /^(.*)$/) { $0 = $1 }
42              
43             =over 4
44              
45             =item RemoveFormValues ( HTML [, HTML [, HTML [...]]] )
46              
47             Removes the form values. Exported by default. Returns an array of lines
48             containing the updated HTML, or one single like containing them separated
49             by newlines.
50              
51             =back
52              
53             =cut
54              
55             # We want to modularize this a lot, and fix it up.
56             sub RemoveFormValues {
57             my $line = join("\n", @_);
58             return undef unless $line;
59              
60             my $form = HTML::Form->parse($line, $0);
61              
62             # Take out the
and
tags
63             $line =~ s%]*>%%isg;
64              
65             # Take out , replacing them with
[...]
66             # (this may not be the best idea; perhaps we should just leave them in?)
67             $line =~ s%<(\s*/?\s*)textarea([^>]*)*>%<$1pre$2>%g;
68              
69             my (%radio);
70              
71             # Take out bits, leaving the 'value' part, unless it's
72             # a 'submit' box, in which case we'll drop it entirely
73             my $i;
74             $line =~ s%(]*>)%
75             my $form = HTML::Form->parse("
$1
", $0);
76             foreach ($form->inputs) {
77             next unless ref $_;
78             $i = "";
79             if ($_->type eq 'submit' || $_->type eq 'reset') { }
80             elsif ($_->type eq 'image' || $_->type eq 'button' ) { }
81             elsif ($_->type eq 'radio') {
82             my $input = $form->find_input($_->name);
83             if ($input->value) { $i = " [X] " unless $radio{$_->name}++ }
84             else { $i = " [ ] " }
85             }
86             elsif ($_->type eq 'checkbox') {
87             my $input = $form->find_input($_->name);
88             $input->value ? $i = " [X] " : $i = " [ ] ";
89             }
90             elsif ($_->type eq 'hidden') { }
91             elsif ($_->type eq 'file') { }
92             elsif ($_->type eq 'password') { $i = $_->value; $i =~ s/./x/g; }
93             elsif ($_->type eq 'text') { $i = $_->value }
94             else { $i = ""}
95             }
96             $i %eisgx;
97              
98              
99             # Now comes the work with 'select'. Just leave these in a form tag.
100             $line =~ s%(]*>.*]*>)%
101             "
$1
" %eisgx;
102              
103             wantarray ? split("\n", $line) : $line;
104             }
105              
106             1;
107              
108             =head1 NOTES
109              
110             This module is a work in progress; I've only got basic functionality
111             working at the moment.
112              
113             =head1 REQUIREMENTS
114              
115             Perl 5 or better, and the C module (with everything that
116             requires).
117              
118             =head1 SEE ALSO
119              
120             B
121              
122             http://www.ks.uiuc.edu/Development/MDTools/dbiframe for the latest version.
123              
124             =head1 TODO
125              
126             Modularize the code.
127              
128             Make some more specific functions, and allow for more customizability
129             within it. IE, it'd be nice to only take out