CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Working with forms ?

 



ACGUY
New User

Nov 8, 2004, 5:33 AM

Post #1 of 5 (1037 views)
Working with forms ? Can't Post

When I put an option radio button or a form text area in frontpage..

How could I using perl to capture the value of the radio button and output it to a file..

I know how to output and write to a file.. but how do I capture the value so I can output the value of the file.. and then perhaps go to another page when the user has clicked on the option or submitted


(This post was edited by ACGUY on Nov 8, 2004, 5:34 AM)


davorg
Thaumaturge / Moderator

Nov 8, 2004, 6:03 AM

Post #2 of 5 (1034 views)
Re: [ACGUY] Working with forms ? [In reply to] Can't Post

You need to load the CGI module and use its "param" method.


Code
use CGI ':cgi'; 

# In this example we're just displaying plain text
print header(-type => 'text/plain');

# Assume the form had an input called "some_input"
my $value = param('some_input');

print "The value of some_input was $value";


Of course, you don't need to display the value like that. You can write it to a file or use it in some conditional processing. Or anything else you might want to do.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


KevinR
Veteran


Nov 8, 2004, 11:30 AM

Post #3 of 5 (1029 views)
Re: [ACGUY] Working with forms ? [In reply to] Can't Post

Yes, use the CGI module to get the form data and then use conditionals to determine what to do with the data.

assume you radio button is called radio1 and you are using the method posted by Dave above...

Radio button values are usually not important, just the fact that they are checked is, unless you have a group of buttons with the same name. We will assume a unique button.


if (param('radio1')) {
go do something useful
}
else {
maybe do something else
}
-------------------------------------------------


ACGUY
New User

Nov 8, 2004, 7:06 PM

Post #4 of 5 (1024 views)
Re: [ACGUY] Working with forms ? [In reply to] Can't Post

Thanks alot for your help!

I am getting the hang of perl using a good book as well..

Just one VERY basic thing that I need to know..

Ok say I am writing a html code.. and in that html code I want to add some small perl commands, how do I do it? or do I write the perl commands uniquely and call them somehow when a particular action happens..

Like, how do I within a html transfering control to a perl interpreter.. or do I type a peice of code at the start of the html to ensure both are immediately supported in the document so long as their is a perl interpreter in the server/or local machine.. agh hope this made sense :)


davorg
Thaumaturge / Moderator

Nov 9, 2004, 1:55 AM

Post #5 of 5 (1018 views)
Re: [ACGUY] Working with forms ? [In reply to] Can't Post

You have a couple of options.

Server Side Include (SSI) is a technology supported by most modern web servers. In this method, certain HTML files are flagged (often by having a .shtml extension) as requiring extra processing as they are being requested by a browser. You can then put special comments into these files which can be a reference to an external program. That program is run and the results are inserted into the page in place of the comment. The best implementation of this is in Apache.

Alternatively, you can build up all of your page from within a CGI program. The best way to do this is using a template system (I recommend the Template Toolkit). Using this method, your CGI program builds up a data structure containing all of the required data which it then passes to the template processor along with the name of a template. The template processor then expands the template, replacing special tags with the contents of the data structure.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives