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

Hi, I am doing a mini project in perl.I need to create a form with fields like employee name,gender,phonenumber,password using html.How cani I use that html file in my perl sript?After clicking submit button the date has to save in database.It has to generate 8 digit uniqe code.I have to do password and phone number validations through perl. Please help with the code.I'm working this on windows Activeperl5.

Replies are listed 'Best First'.
Re: Perl mini project
by marto (Cardinal) on Jun 26, 2019 at 10:38 UTC
Re: Perl mini project
by hippo (Archbishop) on Jun 26, 2019 at 10:42 UTC
Re: Perl mini (web) project -- Dancer2
by Discipulus (Canon) on Jun 26, 2019 at 11:34 UTC
    Hello Ekanvitha9 and welcome to the monastery and to the wonderful world of Perl!

    I'd add to the above Dancer2 because is very easy to start with. Start with the Dancer2::Tutorial

    In my experience, as you are on windows, forget to configure IIS to run your perl code: is a stress and many time with a dead end.

    Go instead with some PSGI (instead of CGI) aware server that can run decently on windows: I had luck with Twiggy with a simple command line launcher:

    C:\perl5.26-64\perl\site\bin\twiggy.bat  --listen 127.0.0.1:80 c:/scripts/miniproject/bin/app.psgi

    See also a mini project of mine using Dancer2 (nothing impressive: was my first serious attempt)

    For the database connection perhaps starting with sqlite is good enough.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Perl mini project
by daxim (Curate) on Jun 26, 2019 at 13:48 UTC
    Save as app.psgi and run with thrall. That will be 200 US dollars, payable to the Perl Foundation.
    use strict; use warnings; use Plack::Request qw(); use HTTP::Status qw( HTTP_OK HTTP_METHOD_NOT_ALLOWED HTTP_CREATED HTTP_UNPROCESSABLE_EN +TITY ); use Authen::Passphrase::Argon2 qw(); use Crypt::URandom qw(urandom); use Number::MuPhone qw(); use WebService::HIBP qw(); use DBI qw(); require DBD::SQLite; my $dbfile = 'Ekanvitha9.sqlite'; my $html = <<'HTML'; <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <body> <form method="POST"> <div> <label for="name">Name:</label> <input type="text" id="name" name="name" /> </div> <div> <label for="gender">Gender:</label> <input type="radio" id="g1" name="gender" value="g1" / +> <label for="g1">DID YOU JUST ASSUME MY GENDER?</label> <input type="radio" id="g2" name="gender" value="g2" / +> <label for="g2">attack helicopter</label> </div> <div> <label for="phone">Phone number:</label> <input type="tel" id="phone" name="phone" /> </div> <div> <label for="passphrase">Pass phrase:</label> <input type="password" id="passphrase" name="passphras +e" /> </div> <input type="submit" /> </form> </body> </html> HTML my $app = sub { my ($env) = @_; my $req = Plack::Request->new($env); if ('GET' eq $req->method) { return $req->new_response( HTTP_OK, ['Content-Type' => 'application/xhtml+xml'], [$ht +ml] )->finalize; } elsif ('POST' eq $req->method) { my $phone = Number::MuPhone->new($req->parameters->get('phone' +)); return $req->new_response( HTTP_UNPROCESSABLE_ENTITY, ['Content-Type' => 'text/plain'], ['invalid phone number ', $phone ? $phone->error : '' ] )->finalize if (not defined $phone) or $phone->error; return $req->new_response( HTTP_UNPROCESSABLE_ENTITY, ['Content-Type' => 'text/plain'], ['wow, that is a really shitty passphrase'] )->finalize if WebService::HIBP->new->password( $req->parameters->get('passphrase') ) > 0; unless (-e $dbfile) { DBI->connect("dbi:SQLite:dbname=$dbfile")->do( 'create table users (id text, name text, gender text, +phone text, passphrase text)' ); } my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile"); $dbh->{sqlite_unicode} = 1; my $sth = $dbh->prepare( 'insert into users (id, name, gender, phone, passphrase) v +alues (?,?,?,?,?)' ); $sth->execute( sprintf('%08d', rand(100_000_000)), $req->parameters->get('name'), $req->parameters->get('gender'), $req->parameters->get('phone'), Authen::Passphrase::Argon2->new( passphrase => $req->parameters->get('passphrase'), salt => urandom(16), cost => 1, factor => '4096M', parallelism => 4, size => 16, )->hash ); return $req->new_response( HTTP_CREATED, ['Content-Type' => 'text/plain'], ['done'] )->finalize; } else { return $req->new_response(HTTP_METHOD_NOT_ALLOWED)->finalize; } };