#!/usr/local/bin/perl -T # Standalone demo for repeatable html input field. use warnings; use strict; use CGI; sub escapeHTML { my($v) = @_; $v =~ s/&/&/g; $v =~ s//>/g; $v =~ s/"/"/g; $v; } our(@nam); our $ownurl = "cpdemo.cgi"; sub hparm { @nam = grep { length } CGI::param("fld-nam"); } sub htop { print qq{Content-Type: text/html; charset=utf-8\n}, qq{\n}, qq{\n}, qq{\n}, q{ Repeatable html input field demo

Repeatable html input field demo

}; # note: do not add a title attribute to the first style sheet but do not delete the one from the second stylesheet or this breaks in konqueror } sub hform { print q{

Clear form

}; my $nrepeat = CGI::param("rep-nam"); $nrepeat = $nrepeat ? int($nrepeat) : 1; defined(CGI::param("add-nam")) and $nrepeat++; $nrepeat < @nam and $nrepeat = @nam; 1 <= $nrepeat or $nrepeat = 1; $nrepeat <= 1022 or $nrepeat = 1022; my @val = @nam; for my $krepeat (0 .. $nrepeat + 0) { print qq{

Name: }; if ($nrepeat - 1 == $krepeat) { print qq{ Add another }; } print q{}; if ($nrepeat == $krepeat) { print qq{ (Too add one more such field, fill all of them and press preview.) }; } print q{

}; # addtpl } print q{\n}; print qq{

}; } sub hout { print q{

\n}; } sub hbot { print qq{\n}; } sub hmain { ${^TAINT} or die "run in taint mode (perl -T) please"; hparm; htop; hform; hout; hbot; } hmain; 1; __END__