0

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.

4
Contributors
3
Replies
5
Views
11 Years
Discussion Span
Last Post by demo
0

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:

perldoc CGI
0

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

// a basic html form

<form action='script.pl' method='post'>
NAME: <input type='text' name='name' size'8' maxlength='8' />
<br />
<input type='submit' name='button' value='Folder Name' />
</form>

// the perl script (script.pl)

#! /usr/lib/perl

use CGI;
use strict;

my $obj = new CGI;

my $name = $obj->param ( 'name' );

my $base = './docs/folders/';

print "Content-type: text/html\n\n"; 

if ( $name eq '' )
{
	print "the directory name was not entered!\n";
}
elsif ( $name !~ m/^[a-z0-9]{1,8}$/i )
{
	print "the directory name was not valid!\n";	
}
else
{
	if ( -e $base . $name )
	{
		print "can not create directory, directory already exists!\n";
	}
	elsif ( ! mkdir ( $base . $name, 0777 ) )
	{
		print "can not create directory\n";
	}
	else
	{
		print "new directory created\n";
	}
}

exit(0);

me!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.