Hi,
I'm a Perl program in Windows 7 32-bit using ActivePerl.
I have created a registration form using HTML and saved this file as Details.html

<!DOCTYPE html> <html> <body> <form name="myform" METHOD="POST" ACTION="D:\Application\perl\cgi-bin\app.pl" onsubmit= "return validation_form()"> <p> <label for="employee name">Employee Name</label> <input type="text" id="employee name" name="employee name" /><br> </p> <p> <label for="password">Password </label> <input type="password" id="password" name="password"/> <div id="errpw"> </div> </p> <p> <label for="dob">DOB </label> <input type="date" id="dob" name="dob"  /> </p> <p> <label for="Gender">Gender</label> <input type="radio" id="gender" name="gender" value="male" /> Male
                <input type="radio" id="gender" name="gender" value="female"/> Female
                <input type="radio" id="gender" name="gender" value="other"/> Other
            </p> <p> <label for="phone number">Phone number</label> <input type="tel" id="Phonenumber" name="Phonenumber"/> </p> <p> <label for="emailid">EmailId</label> <input type="email" id="emailid" name="emailid"/> </p> <p> <label for="ProcessName">Process Name</label> <input type="text" id="ProcessName" name="ProcessName"/> </p> <p> <label for="skillset">Skill Set</label> <input type="text" id="skillset" name="skillset"/> </p> <p> <label for="Designation">Designation</label> <input type="text" id="designation" name="designation"/> </p> <p> <label for="doj">DOJ</label> <input type="date" id="doj" name="doj"/> </p> <p>
                Total Experience
                <select name="number" > <option value="" selected>-</option><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option> <option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option> <option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option> <option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option> <option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option> <option value="30">30</option><option value="31">31</option><option value="32">32</option><option value="33">33</option><option value="34">34</option><option value="35">35</option> <option value="35">35</option><option value="36">36</option><option value="37">37</option><option value="38">38</option><option value="39">39</option><option value="40">40</option> <option value="41">41</option><option value="42">42</option><option value="43">43</option><option value="44">44</option><option value="45">45</option><option value="46">46</option> <option value="47">47</option><option value="48">48</option><option value="49">49</option><option value="50">50</option> </select> </p> <p> <button type="submit">Submit</button> </p> </form> </body> </html>

After clicking Submit button, I have to read the values and also to do password,emailid,& phonenumber validations using Perl script with CGI module.I saved this file as app.pl

#!/usr/bin/perl
print "Content-type: text/html\n\n";
use strict;
use warnings;
use CGI qw(:standard);
$|=1;
my $form = CGI->new;
print $form->header ( );
print "CONTENT_LENGTH = $ENV{'CONTENT_LENGTH'}\n";
if ( $ENV{'REQUEST_METHOD'} eq "POST" ) 
{
    read(STDIN,$form, $ENV{'CONTENT_LENGTH'}); 
}
else 
{
    print "\n At least fill something! I cannot work with empty strings";
    exit;
}

foreach my $pair (split('&', $form))
{        
    if ($pair =~ /(.*)=(.*)/)
    {  
    (my $key,my $value) = ($1,$2);    
    $value =~ s/\+/ /g;  
    $value =~ s/%(..)/pack('c',hex($1))/eg;
    my $inputs{$key} = $value;   
    } 
} 
if ($query->$form('submit'))
{
  process_form ();
}
else
{
  display_form ();
}

sub process_form
{
  if (validate_form())
  {
    print <<END_HTML;
    <html><head><title>Thank You</title></head> <body>
    Thank you - your form was submitted correctly!
    </body></html>
END_HTML
  }
}
sub validate_form{
    my $error="";
    my $password = $inputs{"password"};
    if ($password =~ /^[\w\d@#\$%`~!^&*()_\-+={}[\]|\\'";:\/?.><,]{8}$/ && $error=="") {
        print "Please enter the correct password";
    }
    my $Phonenumber = $inputs{"Phonenumber"};
    @ph=split('',$Phonenumber);
    my $size=@ph;
    if($size==11 &&$error==""){
        if($Phonenumber=!/^[6-9]+\d/)
        {
            $error=("Please enter valid phone number");
        }
    }
    my $emailid = $inputs{"emailid"};
    if($emailid=!/([a-zA-Z]+)(\d+)@([a-zA-Z]+)\.(com|net|org)/ && $error=="")
    {
        $error=("Please enter the valid EmailId");
    }
}

Here the main problem is while running the app.pl file from the command promt, the HTML file is not directly opening in the browser and after submitting ,the values has to save in MySQL database.Please help me with this code.

Thanks in Advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.