#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    2
    Rep Power
    0

    Help with script


    Hi,

    I've used this script to receive data via a post. It works very well.
    However, I would like to improve on the one aspect. If the user does not enter data into one of the fields - for example the Name field - the killnicely function is called. That Great.

    if( $FORM{'a2name'} eq "" )
    {
    killnicely("Name was not entered");
    }


    sub killnicely{
    my($errmsg) = @_;
    print"<h1 align=center><u>Wes French Statues</h1></u>\n";
    print"<hr>\n";
    print"<h3 align=center>Error!</h3>\n";
    print"<p><b></b><br>\n";
    print"<u><b>$errmsg </b></u></p>\n";
    print"<h4>Press the Back button on your browser to return</h4>\n";
    print"<hr>\n";
    print"</body></html>\n";
    exit;
    }

    My main problem is that instead of having the error message take over the web page - and the user having to click back to the Form Page - I would like to either have a window displaying an error message OR to have the cursor advance to the field where the data was not entered.


    Thanks,
    Dave


    -------------------------------------------------------------


    #!/usr/bin/perl

    use warnings;

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

    read( STDIN,$buffer,$ENV{CONTENT_LENGTH} );

    @string = split( /&/,$buffer );

    foreach $str( @string )
    {
    ( $name,$value ) = split( /=/,$str );

    $value =~ tr/+/ /;

    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    $FORM{ $name } = $value;
    }

    if( $FORM{'a2name'} eq "" )
    {
    killnicely("Name was not entered");
    }

    if( $FORM{ 'a3email' } eq "" )
    {
    killnicely("Email address was not entered");
    }

    $count = 0;
    $check1 = 0;
    $check2 = 0;

    $tester = $FORM{ 'a3email' };

    while( $count < 50 )
    {
    $test = chop( $tester );
    if( $test eq "@" )
    {
    $check1 ++;
    }
    if( $test eq "." )
    {
    $check2 ++;
    }
    $count ++;
    }

    if( $check1 != 1 || $check2 < 1 )
    {
    killnicely("Incorrect an email address");
    }

    if( $FORM{'b3street'} eq "" )
    {
    killnicely("Address was not entered");
    }


    if( $FORM{'b5city'} eq "" )
    {
    killnicely("City was not entered");
    }

    if( $FORM{'b6state'} eq "" )
    {
    killnicely("State was not entered");
    }

    if( $FORM{ 'b7zip' } eq "" )
    {
    killnicely("Zip was not entered");
    }

    if( $FORM{ 'c4phone' } eq "" )
    {
    killnicely("No phone number was entered");
    }

    $FORM{ 'myemail' } = 'wesfrench@yahoo.com';
    $FORM{ 'myname' } = 'Wesley French';

    $mailprog= '/usr/lib/sendmail';

    $recipient = $FORM{ 'a3email' };


    open(MAIL, "|$mailprog -t") or dienice("Can't access $mailprog!\n");

    print MAIL "To: $recipient\n";

    print MAIL "Reply-to: $FORM{'myemail'} ($FORM{'myname'})\n";

    print MAIL "Subject: Wes French's Statues !\n\n";

    print MAIL "Thanks for your inquiry : $FORM{'a2name'}\n";

    print MAIL "Allow 2 days for your application to be processed\n";

    print MAIL "IP Address of visitor : $ENV{ 'REMOTE_ADDR' }\n";
    print MAIL "Name : $FORM{ 'a2name' }\n";
    print MAIL "Address : $FORM{ 'b3street' }\n";
    print MAIL "City : $FORM{ 'b5city' }\n";
    print MAIL "State : $FORM{ 'b6state' }\n";
    print MAIL "Zip : $FORM{ 'b7zip' }\n";
    print MAIL "Home Phone : $FORM{ 'c4phone' }\n";
    print MAIL "Email Mail : $FORM{ 'a3email' }\n";
    print MAIL "\n\n";
    print MAIL "Comments\n";
    print MAIL "$FORM{ 'z0comments' }\n";

    close( MAIL );

    open(MAIL, "|$mailprog -t") or dienice("Can't access $mailprog!\n");

    print MAIL "To: $FORM{ 'myemail' }\n";

    print MAIL "Subject: Visitor !\n\n";

    print MAIL "IP Address of visitor : $ENV{ 'REMOTE_ADDR' }\n";
    print MAIL "Name : $FORM{ 'a2name' }\n";
    print MAIL "Address : $FORM{ 'b3street' }\n";
    print MAIL "City : $FORM{ 'b5city' }\n";
    print MAIL "State : $FORM{ 'b6state' }\n";
    print MAIL "Zip : $FORM{ 'b7zip' }\n";
    print MAIL "Home Phone : $FORM{ 'c4phone' }\n";
    print MAIL "Email Mail : $FORM{ 'a3email' }\n";

    print MAIL "\n\n";
    print MAIL "Comments\n";
    print MAIL "$FORM{ 'z0comments' }\n";

    close( MAIL );

    print<<HeaderStart;
    <html><head><title>Customer's Inquiry</title></head>
    <body bgcolor = "#00FFFF" >
    <p>
    <b>

    <h30><b>Thanks for visiting<b></h30>

    <h31>IP Address of visitor : $ENV{ 'REMOTE_ADDR' }</31>
    <h32> Name : $FORM{ 'a2name' }</32></p>
    <h32> Address : $FORM{ 'b3street' }</33></p>
    <h34> City : $FORM{ 'b5city' }</h34></p>
    <h35> State : $FORM{ 'b6state' }</h35></p>
    <h36> Zip : $FORM{ 'b7zip' }</h36></p>
    <h37> Phone : $FORM{ 'c4phone' }</h37></p>
    <h38>Email Mail : $FORM{ 'a3email' }<h/38></p>
    <H39>COMMENTS</H39></p>
    <H40>$FORM{ 'z0comments' }</40></p>

    HeaderStart


    print<<HeaderEnd;
    </b>
    </p>
    </body
    </html>
    HeaderEnd

    sub dienice {

    my($errmsg) = @_;
    print"<h1 align=center><u>Wes French Statues</h1></u>\n";
    print"<hr>\n";
    print"<h3 align=center>Error!</h3>\n";
    print"<p><b></b><br>\n";
    print"<u>$errmsg </u></p>\n";
    print"</body></html>\n";
    exit;
    }


    sub killnicely{
    my($errmsg) = @_;
    print"<h1 align=center><u>Wes French Statues</h1></u>\n";
    print"<hr>\n";
    print"<h3 align=center>Error!</h3>\n";
    print"<p><b></b><br>\n";
    print"<u><b>$errmsg </b></u></p>\n";
    print"<h4>Press the Back button on your browser to return</h4>\n";
    print"<hr>\n";
    print"</body></html>\n";
    exit;
    }
  2. #2
  3. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    1,614
    Rep Power
    18
    webM

    for $i(0..20){for($j=0;$j<=$i;$j+=2){print pack(qq{H2},
    substr(qq{5f5745424d415354415f},$j,2));}print qq{\n};};

IMN logo majestic logo threadwatch logo seochat tools logo