Advertisement

04.08.2002 at 05:21PM PDT, ID: 20286279
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

trouble with optional and required fields in a form

Asked by nadiassdcg in Perl Programming Language

Tags: , , ,

I have this script from an e-mail form:

#!/usr/local/bin/perl

$|++;      ##      Disable output buffering.

use CGI;

$q=new CGI;

$err_ctr=0;      ##      Initailize the error count.

##      Read the incoming HTML variables into Perl variables.
##      The Perl variables have the same name as the HTML form variables.
foreach ($q->param){
      $$_=$q->param($_);
      $$_=~ s/^\s+//g;
      $$_=~ s/\s+$//g;

      if (/^cp$/ || /^celular$/ || /^tel_oficina$/||/^extension$/|| /^dia_hora_entrega$/){
 next;      ##      Ignore this optional field.
      if (!($$_)){      ##      Check if any of the mandatory fields are empty.
            print "Content-type: text/html\n\n" if (!($err_ctr));
            print "<B><FONT COLOR=RED>$_ cannot be empty.</FONT></B><BR>\n";
            ++$err_ctr;      ##      Increment the error count.
      }else{
            ##      Build the plain text message of the email.
            $plain_text.=$_." = ".$$_."\n";
            #print $_," = ",$$_,"<BR>\n";
      }
}

if ($err_ctr){      ##      We do have some error messages!!
      exit;      ##      Bail out!!
}

$boundary="Message-Boundary-19990614";
$from='Web<>';

push(@attachments,$file);

##      Prepare to send out the email to you, the owner of the site.
$mailprog ="/usr/lib/sendmail";
open(MAIL, "| $mailprog -t ") || die "Content-type: text/html\n\n$!";
print MAIL "To: $recipient\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject!\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-type: Multipart/1;\n";
print MAIL "\tboundary=$boundary\n";
print MAIL "\n";
print MAIL "\n";
print MAIL "--$boundary\n";

##      Add the plain text message to the email
if ($plain_text){
      print MAIL "Content-type: text/plain; charset=US-ASCII\n";
      print MAIL "Content-description: Mail message body\n";
      print MAIL "Content-transfer-encoding: 7BIT\n";
      print MAIL "\n";
      print MAIL $plain_text."\n";
      print MAIL "--$boundary\n";
}

##      Attach all the files to the email
foreach $file (@attachments){
      undef $some_text;

      ##  Read 1024 bytes at a time
      while($bytesread=read($file,$data,1024)){
            $content.=$data;    ##  Store the ACTUAL file content
      }
      close($file);

      $some_text=&encode_base64($content);

      ##      Convert all \'s to /
      $file=~ s/\\/\//g;

      ##      Extract the name of the file.
      $file=~ /.*\/(.*)/;
      $actual_file=$1;

      ##  Print the header for that attachment.
      print MAIL "Content-type: application/octet-stream; name=\"".$actual_file."\"; type=Unknown\n";
      print MAIL "Content-transfer-encoding: BASE64\n";
      print MAIL "Content-disposition: attachment\n";
      print MAIL "\n";
            
      ##  Send out the contents!!
      print MAIL $some_text;
      print MAIL "\n";
      print MAIL "--$boundary\n";
}

##      Send the Email!!
print MAIL "--$boundary--\n";
close(MAIL);

##      Prepare to send out the "Thank you" email to the user.
$mailprog ="/usr/lib/sendmail";
open(MAIL, "| $mailprog -t ") || die "Content-type: text/html\n\n$!";
print MAIL "To: $E_MAIL\n";
print MAIL "From: $from\n";
print MAIL "Subject: Gracias por llenar nuestro formulario. \n";
print MAIL "Estimado usuario:\n\nSu información ha sido recibida.\nEn breve nos comunicaremos con usted.\n\nAtentamente\n\nSelective Directory";
print MAIL "\n";
close(MAIL);

##      Now redirect the user to some page.
print "Location: $redirect\n\n";

sub encode_base64 ($;$){
  my $res = "";
  my $eol = $_[1];
  $eol = "\n" unless defined $eol;
  pos($_[0]) = 0;                          # ensure start at the beginning
  while ($_[0] =~ /(.{1,45})/gs) {
    $res .= substr(pack('u', $1), 1);
    chop($res);
  }
  $res =~ tr|` -_|AA-Za-z0-9+/|;               # `# help emacs
  # fix padding at the end
  my $padding = (3 - length($_[0]) % 3) % 3;
  $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
  # break encoded string into lines of no more than 76 characters each
  if (length $eol) {
    $res =~ s/(.{1,76})/$1$eol/g;
  }
  $res;
}


but it sends an error:

Missing right curly or square bracket at /home/cgi-bin/head_hunters1.pl line 129, at end of line
syntax error at /home/cgi-bin/head_hunters1.pl line 129, at EOF
Execution of /home/cgi-bin/head_hunters1.pl aborted due to compilation errors.

the only part of the script I changed is the one about optional fields:

if (/^cp$/ || /^celular$/ || /^tel_oficina$/||/^extension$/|| /^dia_hora_entrega$/){
next;     ##     Ignore this optional field.

but if I write this instead:

next if /^cp$/;
next if /^celular$/;
next if /^CP$/;
next if /^tel_oficina$/;

it doesn´t sends an error, and it doesn´t ask for the fields to be filled, but if I fill them when I receive the email from the form the information from those fields don´t appear in itStart Free Trial
[+][-]04.08.2002 at 05:25PM PDT, ID: 6926798

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2002 at 05:50PM PDT, ID: 6926852

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2002 at 05:51PM PDT, ID: 6926856

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2002 at 06:00PM PDT, ID: 6926877

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2002 at 07:02PM PDT, ID: 6926990

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2002 at 10:57PM PDT, ID: 6927400

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2002 at 11:44PM PDT, ID: 6927455

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.09.2002 at 05:47PM PDT, ID: 6930044

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.09.2002 at 05:48PM PDT, ID: 6930048

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.09.2002 at 06:59PM PDT, ID: 6930168

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: attachments, email, field, optional
Sign Up Now!
Solution Provided By: maneshr
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.09.2002 at 07:30PM PDT, ID: 6930225

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32