944,183 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 8490
  • Perl RSS
May 25th, 2006
0

Form data as input into Perl code

Expand Post »
Please help me with how to use client inputs in a form as part of arguments in a CGI script following a button return. I want a client to specify a name which i can then use in perl script to create a folder for that client.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
brounemmanuel is offline Offline
7 posts
since May 2006
May 25th, 2006
0

Re: Form data as input into Perl code

Try using the CGI module. It makes doing CGI development in Perl extremely easy (at least the CGI bits).

Try this at a command line:
Perl Syntax (Toggle Plain Text)
  1. perldoc CGI
Reputation Points: 11
Solved Threads: 5
Light Poster
azimuth0 is offline Offline
36 posts
since May 2006
May 25th, 2006
0

Re: Form data as input into Perl code

Yes, the CGI module is your friend:

http://perldoc.perl.org/CGI.html
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Jun 1st, 2006
0

Re: Form data as input into Perl code

A simple example... (note: more validation should be done, this is just an example...)

// a basic html form

Perl Syntax (Toggle Plain Text)
  1. <form action='script.pl' method='post'>
  2. NAME: <input type='text' name='name' size'8' maxlength='8' />
  3. <br />
  4. <input type='submit' name='button' value='Folder Name' />
  5. </form>


// the perl script (script.pl)

Perl Syntax (Toggle Plain Text)
  1. #! /usr/lib/perl
  2.  
  3. use CGI;
  4. use strict;
  5.  
  6. my $obj = new CGI;
  7.  
  8. my $name = $obj->param ( 'name' );
  9.  
  10. my $base = './docs/folders/';
  11.  
  12. print "Content-type: text/html\n\n";
  13.  
  14. if ( $name eq '' )
  15. {
  16. print "the directory name was not entered!\n";
  17. }
  18. elsif ( $name !~ m/^[a-z0-9]{1,8}$/i )
  19. {
  20. print "the directory name was not valid!\n";
  21. }
  22. else
  23. {
  24. if ( -e $base . $name )
  25. {
  26. print "can not create directory, directory already exists!\n";
  27. }
  28. elsif ( ! mkdir ( $base . $name, 0777 ) )
  29. {
  30. print "can not create directory\n";
  31. }
  32. else
  33. {
  34. print "new directory created\n";
  35. }
  36. }
  37.  
  38. exit(0);

me!
Reputation Points: 10
Solved Threads: 2
Newbie Poster
demo is offline Offline
18 posts
since Jan 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Executing Server Applications remotely
Next Thread in Perl Forum Timeline: GUI of desktop applications





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC