25 users online (2 members and 23 guests)  


  Results 1 to 6 of 6

Related

  1. required fields in a form    Forum: HTML Forum
    Replies: 17
  2. HTML Form with required fields    Forum: HTML Forum
    Replies: 10
  3. Required Form Fields    Forum: Javascript Forum
    Replies: 1
  4. Replies: 3
  1. #1
    CoralM's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Location
    London
    Posts
    2

    Required fields (perl)

    Does anyone know why the following cgi script (perl) doesn't work and what I should do to fix it? I have fields in the HTML form named 'Firstname', 'Surname' and 'registeredaddress' which I want to make mandatory. The script excluding the lines referring to the mandatory fields (which is between the 2 sets of ##) works fine.

    Please bear in mind that my level of knowledge is very low, when you reply!

    Thanks.



    #!/usr/bin/perl

    use CGI;

    CGI::ReadParse(*in);

    ##
    if ($in{'Firstname'} eq "" or $in{'Surname'} eq "" or $in{'registeredaddress'} eq "" or
    $in{'Email'} eq "" ) {
    dienice("Please fill out the fields marked with *.");
    }

    ##

    print "Content-type:text/html\n\n";
    print "<HTML><HEAD><TITLE>form results</TITLE></HEAD>\n\n";
    print "<BODY BGCOLOR='FFFFFF'>\n\n";
    print "<h2>We would like to thank you for your form submission. We will contact you within the next few days.</h2>\n";
    print "<br><br>\n\n";

    $file = 'fileI'msavingto.txt';

    open(FILE, ">>$file") || die "Can't open $file\n\n";
    flock(FILE, 2) || die "Can't lock $file\n\n";
    foreach $i (keys %in) {
    print FILE "$i:$in{$i}\t";
    }
    print FILE "\n";
    close(FILE) || die "Can't close $file\n\n";

  2. #2
    Derek's Avatar
    Be Yourself

    Status
    Offline
    Join Date
    Aug 2001
    Location
    St. George, Utah, USA
    Posts
    466
    I'm not perl expert but this could be a problem:

    Code:
    $file = 'fileI'msavingto.txt';
    I'm talking about the apostraphie in the the name of the file. Just checking, that might not be the name of your file, if it isn't then always put the right names for everything when you give code and ask for help.

  3. #3
    CoralM's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Location
    London
    Posts
    2
    Thanks for replying, but actually, that's just a name I substituted for the real text file address, as it's potentially secret. The problem is with the script lines between the ## signs, but I don't know what.


    Quote Originally Posted by Derek
    I'm not perl expert but this could be a problem:

    Code:
    $file = 'fileI'msavingto.txt';
    I'm talking about the apostraphie in the the name of the file. Just checking, that might not be the name of your file, if it isn't then always put the right names for everything when you give code and ask for help.

  4. #4
    newhorizonz's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    3
    Quote Originally Posted by CoralM
    Does anyone know why the following cgi script (perl) doesn't work and what I should do to fix it? I have fields in the HTML form named 'Firstname', 'Surname' and 'registeredaddress' which I want to make mandatory. The script excluding the lines referring to the mandatory fields (which is between the 2 sets of ##) works fine.

    Please bear in mind that my level of knowledge is very low, when you reply!

    Thanks.



    #!/usr/bin/perl

    use CGI;

    CGI::ReadParse(*in);

    ##
    if ($in{'Firstname'} eq "" or $in{'Surname'} eq "" or $in{'registeredaddress'} eq "" or
    $in{'Email'} eq "" ) {
    dienice("Please fill out the fields marked with *.");
    }

    ##

    print "Content-type:text/html\n\n";
    print "<HTML><HEAD><TITLE>form results</TITLE></HEAD>\n\n";
    print "<BODY BGCOLOR='FFFFFF'>\n\n";
    print "<h2>We would like to thank you for your form submission. We will contact you within the next few days.</h2>\n";
    print "<br><br>\n\n";

    $file = 'fileI'msavingto.txt';

    open(FILE, ">>$file") || die "Can't open $file\n\n";
    flock(FILE, 2) || die "Can't lock $file\n\n";
    foreach $i (keys %in) {
    print FILE "$i:$in{$i}\t";
    }
    print FILE "\n";
    close(FILE) || die "Can't close $file\n\n";
    Do you have a subroutine called dienice anywhere in the script - if not you need one! then change this line:

    dienice("Please fill out the fields marked with *.");

    to:

    &dienice("Please fill out the fields marked with *.");

    If you're still stuck post a message in our forums at
    Last edited by QuietDean; 12-02-2003 at 05:35 PM.

  5. #5
    ryche88om's Avatar
    New User

    Status
    Offline
    Join Date
    Dec 2003
    Posts
    1

    Lightbulb Sub dienice - try this!!

    if ($FORM{'name'} eq "") {
    &dienice("Please fill out <U>name</U>");
    }
    if ($FORM{'email'} eq "") {
    &dienice("Please fill out <U>email</U>");
    }
    if ($FORM{'offer'} eq "") {
    &dienice("Please fill out <U>offer</U>");
    }




    sub dienice {
    my($msg) = @_;
    print "<h2>Error</h2>\n";
    print $msg;
    exit;
    }

  6. #6
    bresticals's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2004
    Location
    england.
    Posts
    7
    it's also worth trying something like ;

    if ( ! $foo || $foo eq '' ) { print "foo not entered" }

    also in Perl you dont need the & at the start of a sub.



Tags for this Thread