Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Perl CGI Text box

by PyrexKidd (Monk)
on Oct 29, 2010 at 17:24 UTC ( [id://868363]=perlquestion: print w/replies, xml ) Need Help??

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

I have a CGI Script that processes some input and generates a file based on the input and a template stored on the server.
I need to be able to edit the templates from a GUI instead of the CLI. I would like to do something similar to the trixbox GUI Config File Editor, except in Perl instead of PHP.

I am using a form with a text field (something like the text box I am typing in now) to do the editing; I can save text entered in the text box to a file, but how do I load text into the text field?

Perhaps I am approaching this the wrong way, I'd like to avoid reinventing the wheel, maybe someone can suggest a better solution?

Thanks for the assist.

Replies are listed 'Best First'.
Re: Perl CGI Text box
by Anonymous Monk on Oct 29, 2010 at 18:21 UTC
    $ perl -MCGI -le " print q!<textarea>!, CGI->escapeHTML( 2), q!</texta +rea>! " <textarea>2</textarea> $ perl -MCGI -le " print CGI->textarea( 1,2,3,4) " <textarea name="1" rows="3" cols="4">2</textarea> $ perl -MCGI -le " print CGI->textarea( qw! -name 1 -default 2 -riows +3 -cols 4 !) " <textarea name="1" cols="4" riows="3">2</textarea> $
    CGI::FormBuilder/CGI::Application/Catalyst/http://www.catalystframework.org/
Re: Perl CGI Text box
by jethro (Monsignor) on Oct 29, 2010 at 17:51 UTC
    Just put the default text between starttag and endtag of the textarea (or textbox) tag.

    If this is not the answer you are looking for, you have to be more specific. I.e. show us your code. Tell us which html tag you are using. Is your problem the coding or the html?

Re: Perl CGI Text box
by PyrexKidd (Monk) on Nov 02, 2010 at 04:53 UTC
    Ok,
    Essentially I am trying to read a file into an array, and
    then display the contents of the array inside the text box.
    My eventual goal is to display XML text from a file in the text area.
    here is the code I am using:
    #!/usr/bin/perl -T use strict; use warnings; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $cgi = new CGI; print $cgi->header(); print $cgi->start_html('My test text box'); print $cgi->startform; open my $FHIN, '<', "./test.file" || die "$!"; my @fhin = <$FHIN>; print $cgi->textarea( -name=>'TEXT_AREA', -default=>"@fhin"); print "<textarea> @fhin </textarea>"; print $cgi->end_html();


    this produces two empty text boxes. running this from the command line results in:
    Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>My test text box</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <form method="post" action="http://localhost" enctype="application/x-w +ww-form-urlencoded"> <textarea name="TEXT_AREA" >this is a test file this is line two three 4 foo bar six </textarea><textarea> this is a test file this is line two three 4 foo bar six </textarea> </body>
    So I know the text is being read into the array. But looking at the source of the page shows no text is being passed:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>My test text box</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <form method="post" action="/cgi-bin/cfg_edit.cgi" enctype="applicatio +n/x-www-form-urlencoded"> <textarea name="TEXT_AREA" ></textarea><textarea> </textarea> </body> </html>

    and this is the contents of my test.file:
    this is a test file this is line two three 4 foo bar six

      This indicates that your cgi script when called from the web server doesn't find or can't read your file. And that's why it is empty.

      You use ./textfile. Naturally your webserver has not the same "current directory" as you have. Use an absolute path and one where you know the webserver has access to

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://868363]
Approved by sundialsvc4
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (9)
As of 2024-04-23 17:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found