# This code is provided "as is" with NO WARRANTY expressed or # implied. You may use it freely at your own risk. #!/usr/bin/perl use CGI; $query = new CGI; print $query->header; $docpath = '/home/httpd/html/'; $html_path = "$docpath/my_form.html"; $html_file = `cat $html_path`; @texttypes = getTexts($html_file); foreach (@texttypes) { $val = $query->param($_); $val =~ s/"/"/g; $html_file =~ s/(]*)(name="?$_"?)([^>]*>)/$1 $2 value="$val" $3/is; } @selects = getSelects($html_file); foreach (@selects) { $name = selectName($_); $new_select = $_; $val = $query->param($name); if (/value="$val"/i) { $new_select =~ s/(/$1 SELECTED>/si; } else { $new_select =~ s/(\s*$val)/$1 SELECTED$2/si; } $html_file =~ s/$_/$new_select/si; } @radios = getRadios($html_file); foreach(@radios) { $val = $query->param($_); $html_file =~ s/(value="?$val[^>]*)>/$1 CHECKED>/si; } @cbs = getCheckBoxes($html_file); foreach(@cbs) { $val = $query->param($_); if (length($val) > 0) { $html_file =~ s/(name="?$_[^>]*)>/$1 CHECKED>/si; } } @tas = getTextAreas($html_file); foreach (@tas) { $val = $query->param($_); $html_file =~ s/(]*name="?$_[^>]*>)([\w\-\s]*)(<\/textarea>)/$1$2$val$3/is; } print $html_file; sub getTexts { my($html) = @_; my @t = (); my @texts = split(/