Lady_Aleena has asked for the wisdom of the Perl Monks concerning the following question:

In the script below, how do I get $text_input to change when the submit button is clicked?

#!/usr/bin/perl use strict; use warnings; use CGI; print "content-type: text/html \n\n"; my @family = qw(serif sans-serif cursive fantasy monospace); my @size = qw(xx-small x-small small medium large x-large xx-large); my @weight = qw(normal bold 100 200 300 400 500 600 700 800 900); my @variant = qw(normal small-caps); my @style = qw(normal italic oblique); my $cgi = CGI->new(); my $text_input = $cgi->param('text') || "The quick brown fox jumped ov +er a lazy dog."; print <<"sec1"; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/T +R/html4/strict.dtd"> <html><head><title>Font Test</title> <style type="text/css"> h1 {font-size:14pt;} h2 {font-size:12pt;} p {border:1px #333 solid;} </style> </head> <body> <h1>Font comparisons</h1> <form action="$ENV{REQUEST_URI}" method="get"> <div> <input type="text"/> <input type="submit" value="submit"/> </div> </form> sec1 for my $style (@style) { for my $variant (@variant) { for my $weight (@weight) { for my $size (@size) { for my $family (@family) { print qq{<h2>Style: $style; Variant: $variant; Weight: $weig +ht; Size: $size; Family: $family</h2>\n}; print qq{<p style="font:$style $variant $weight $size $famil +y">$text_input</p>\n}; } } } } } print "</body></html>";

A link to the page.

Have a nice day!
Lady Aleena

Replies are listed 'Best First'.
Re: Reload a script with a new value for input when submit is clicked on an html form
by ikegami (Patriarch) on Feb 23, 2010 at 16:43 UTC

    [ The OP has been updated to incorporate the following code. Originally, it didn't use CGI, and $text_input was initialised from the constant unconditionally. ]

    use CGI; my $cgi = CGI->new(); my $text_input = $cgi->param('text') || "The quick brown fox jumped ov +er a lazy dog.";

    Update: Added missing ";" as per reply.

      That did not work with the above script, though I did catch the missing semicolon at the end of line 3. Could it be that I am using the wrong action or method in the form? The methods get and post did not change the result, so I am leaning more towards action as the culprit. I looked through CGI for the answer, but I am coming up blank. I am reading through it again.

      Have a nice day!
      Lady Aleena
        <input type="text"/> <input type="submit" value="submit"/>
        should be
        <input type="text" name="text"> <input type="submit" value="submit">

        You didn't name the input field, so it wasn't getting sent to the server. Also, that slash is illegal HTML (although some browsers ignore it).

        Both GET and POST will work, but I'd recommend GET here since the request has no side-effects.

Re: Reload a script with a new value for input when submit is clicked on an html form
by molecules (Monk) on Feb 23, 2010 at 18:31 UTC

    Could you please post your current code?

    By the way, this works: http://www.xecu.net/fantasy/files/perl/font.pl?text=howdy

      Code updated above.

      Have a nice day!
      Lady Aleena