Loading ...
Sorry, an error occurred while loading the content.

Re: using undefined values in form submission

Expand Messages
  • Damien Carbery
    ... In one line, to check and set the wmv parameter: $file = ( defined $form- param( wmv ) ) ? $form- param( wmv ) : $file_from_db; You will replace the
    Message 1 of 5 , Nov 6, 2003
    • 0 Attachment
      --- In perl-beginner@yahoogroups.com, "mandwahlin" <mandwahlin@m...>
      wrote:
      > Thanks brad, I am using a flatfile db. this is what i'm playing with
      > at the mo
      >
      > I found a bit of info on ... if(param()) and if(ok()) but I want to
      > have a condition if the param('wmv') is empty then not to error but
      > to continue parsing the form replacing the empty param with stored
      > data...the following will hopefully explain what i'm trying do
      >
      >
      > #!/bin/perl -w
      > use strict;
      > use CGI;
      > use CGI::Carp qw(fatalsToBrowser);
      >
      > # Variable declaration
      > my
      > ($form,$comments,$date,$key,$usr,$db,$dbv,@dbdata,@column,$line,$up_di
      > r,$file,$upload_filehandle,$type,$JSCRIPT);
      >
      >
      >
      >
      > if(param()) {
      >
      > $form = new CGI;
      > $comments = $form->param('comments');
      > $file = $form->param('wmv');
      > $date = $form->param('sysDt');
      > $usr = $form->param('username');
      > $key = $form->param('key');
      >
      > if(ok()) {
      >
      > ##check filetype is correct#####################
      > $type = $form->uploadInfo($upload_filehandle)->{'Content-Type'};
      > unless ($file =~ /\.wmv$/) {
      > print "<script>alert('WMV FILES ONLY!\\n\\nSorry $usr, You can only
      > send us Windows Media Video files.\\n\\nPlease search the FAQ section
      > for help\\n\\nThe Looplounge Team :)\\n\\nClick ok to be redirected
      > back to the form')</script>";
      > require "redirects.pl";
      > &redirects;
      > exit;
      > } else{
      > ###if filetype ok then up the file###################
      > open UPLOADFILE, ">$up_dir/$file";
      > binmode UPLOADFILE;
      > while ( <$upload_filehandle> )
      > {
      > print UPLOADFILE;
      > }
      > close UPLOADFILE;
      >
      > ##overwrite existing entry (thus only ever 1 line entry)#############
      > open (FILE, ">database.txt");
      > print FILE $comments."\|".$file."\|".$date."\n";
      > close(FILE);
      > }
      >
      > } else{
      > ######I made up the following line and it is not real code##########
      > if(param('wmv') undef {
      > ####open up the database file and grab existing entries#############
      > open (FILE, "<database.txt");
      > @dbdata = <FILE>;
      > close(FILE);
      >
      > foreach $line (@dbdata) {
      > $line=~ s/\n//g;
      > @column=split /\|/, "$line";
      >
      > ##add the new comments and date but keep the wmv filename#############
      > open (FILE, ">database.txt");
      > print FILE $comments."\|".$column[1]."\|".$date."\n";
      > close(FILE);
      > }
      >
      >
      > Am I heading, with the wrong syntax, in the right direction?
      > I hope that my ineptness doesn't offend
      > Cheers
      > mand

      In one line, to check and set the 'wmv' parameter:

      $file = ( defined $form->param('wmv') ) ? $form->param('wmv') :
      $file_from_db;

      You will replace the '$file_from_db' with code that returns the value
      from the db.
      The multi line version is:

      if ( defined $form->param('wmv') )
      {
      $file = $form->param('wmv');
      }
      else
      {
      $file = $file_from_db;
      }
    Your message has been successfully submitted and would be delivered to recipients shortly.