Wijaya Edward wrote:

: Is there a way to determine the size of a parameter of a
: textarea or filefield in CGI.pm?

    You can determine the length (using the length() function)
of a field, but not the size of the control on the form. That
information is not sent via the Common Gateway Interface. The
CGI specification is available here.

http://hoohoo.ncsa.uiuc.edu/cgi/


#!/usr/bin/perl

use strict;
use warnings;

use CGI qw/param/;

# Simulate form input.
param( foo => "Text from\na textarea control\n" );

print length param( 'foo' );

__END__

    You could hide information about form field sizes
in hidden fields in the form. Here's is a meta field
hidden in a form which also has a textarea by the name
textarea_1 with 5 rows and 40 columns.

<input type="hidden" name="textarea_1_meta" value="5,40">

#!/usr/bin/perl

use strict;
use warnings;

use CGI qw/param/;

# Simulate form input.
param( textarea_1       => "Text from\na textarea control.\n" );
param( textarea_1_meta  => '5,40' );

print form_field_stats( textarea_1 => 'textarea' );

sub form_field_stats {
    my( $field, $type ) = @_;

    return unless $type eq 'textarea';

    my( $rows, $columns ) = split ',', param( $field . '_meta' );

    return sprintf
        qq|The textarea "$field" is %s characters long.\n| .
        qq|\tIt is %s rows by %s columns wide.\n|,
        length param( $field ),
        $rows,
        $columns;
}

__END__




HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to