Gossamer Forum
Home : Products : DBMan : Customization :

File Upload 2 Mod killed my zeros.

Quote Reply
File Upload 2 Mod killed my zeros.
Continuation of
Field (Can not be left blank) when value == 0?

Okay, I started a new thread for my problem because the problem has changed dramatically from what I thought it was.

The original problem was that when the add form was submitted, all fields with a value of 0 (zero) changed to a value of nothing thus returning an error message for required fields "FieldName (Can not be left blank)".

After some help from the forum and a little trial and error I narrowed the problem down to the File Upload 2 Mod. Somewhere in the mod, 0 is replaced with ' ' (blank).

Anybody know of a fix for this:

When new records are added to the database, instead of 0 (zero) being added as the value of the field, only a blank is added to the database.
As a result, if the field happens to be a required field, an error message is returned.
This is true of any and all fields where the value entered is 0.
By the way, 00 (double zero) is added to the database correctly.

I have tested repeatedly and the problem only occurs when the File Upload 2 Mod is used.

How do I prevent the File Upload 2 Mod from replacing zeros with blank entries. This happens for select, text, and textarea using either 'alpha' or 'numer' definitions. Additionally, being a required field or default value does not dictate whether or not zero turns to blank.

I've tried defining valid entries to include 0 but this didn't help either.


Thanks for any help or ideas.
beetlemanTongue

Marcus L. Griswold
Quote Reply
Re: [beetleman] File Upload 2 Mod killed my zeros. In reply to
I really don't believe your problem is being caused by the Upload mod. I had the same problems when creating a database for hockey stats. There was no way to include the default value of just 0.

What I did was set the default values in the .cfg file as either:

'G' => [ 9,'alpha',5,4,0,'00',''], # goals

or

'GA' => [15,'alpha',5,5,0,'--',''],## goalie

This database did not use the upload mod, so that is how I know it was just the way DBMan handles the value of 0.

I never did find a way to do it differently.

Hope this helps

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] File Upload 2 Mod killed my zeros. In reply to
I tried again to get thing up and running but I still can't get 0 to save to the database. The only reason I suspect the Upload mod is that I only have the problem when it is installed. After I restored the cgi, cfg, and html.pl to non-upload, everything worked again. Then I tried again to add the mod and the problem with the zeros happened again.

The problem doesn't only happen to fields where 0 is the default value. Even if no default value or a non-zero default value is defined, when 0 is entered into the field, it is not saved as 0, just a blank space in the database. This occurs in every field where zero is entered either by default or by the user.

I will restore my original files again and try to add the mod once again with hopes that this has been an installation error.

By the way, on my add form, all default values show up correctly including zeros from just my cfg. So, I'm not really sure if I understand the problem you described.

Thanks,
beetlemanTongue

Marcus L. Griswold
Quote Reply
Re: [beetleman] File Upload 2 Mod killed my zeros. In reply to
Okay, I narrowed the bug down to db.cgi sub parse_form.

In the File Upload Mod, the original sub parse_form below:

Code:
sub parse_form {
# --------------------------------------------------------
# Parses the form input and returns a hash with all the name
# value pairs. Removes SSI and any field with "---" as a value
# (as this denotes an empty SELECT field.

my (@pairs, %in);
my ($buffer, $pair, $name, $value);

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
&cgierr ("This script must be called from the Web\nusing either GET or POST requests\n\n");
}
PAIR: foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

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

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

$value =~ s/<!--(.|\n)*-->//g; # Remove SSI.
if ($value eq "---") { next PAIR; } # This is used as a default choice for select lists and is ignored.
(exists $in{$name}) ?
($in{$name} .= "~~$value") : # If we have multiple select, then we tack on
($in{$name} = $value); # using the ~~ as a seperator.
}
return %in;
}

Is replaced by this:

Code:
sub parse_form {
# --------------------------------------------------------
my (%in);
my ($buffer, $pair, $name, $value);

PAIR: foreach $name ($query->param()) {
$value = $query->param("$name");

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

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

$value =~ s/<!--(.|\n)*-->//g; # Remove SSI.
if ($value eq "---") { next PAIR; } # This is used as a default choice for select lists and is ignored.
unless ($value) { next PAIR; }
(exists $in{$name}) ?
($in{$name} .= "~~$value") : # If we have multiple select, then we tack on
($in{$name} = $value); # using the ~~ as a seperator.
}
return %in;
}

In the original code, I have no problems with my zeros disapearing.
The problem ONLY occurs in the new code.

Please help.

Thanks,
beetlemanTongue

Marcus L. Griswold
Quote Reply
Re: [beetleman] File Upload 2 Mod killed my zeros. In reply to
I found it!

In db.cgi sub parse_form for the File Upload Mod, the following line kills zeros:
Code:
unless ($value) { next PAIR; }

It appears that the line check to see if there is a value entered in the field. Because numerically, 0 has no value, it mistakenly parses the field value as nothing. So how can I rewrite the statement to allow zeros and still handle blank fields correctly?

Thanks,
beetlemanTongue

Marcus L. Griswold
Quote Reply
Re: [beetleman] File Upload 2 Mod killed my zeros. In reply to
I am thinking you could evaluate the length of $value, such that a blank has a length of 0 and a 0 has a length of 1.

I looked quickly to see if I could find a function for the length of a variable, but could not find it.

edit, I found this

http://www.perldoc.com/...pod/func/length.html

Last edited by:

joematt: Apr 30, 2003, 2:14 PM
Quote Reply
Re: [joematt] File Upload 2 Mod killed my zeros. In reply to
Hey thanks for the reply joematt.

I was thinking that perhaps a conditional statement that checks to see if the field is blank instead of no-value.

Would
if ($value eq "" || $value == 0 || $value == null) { next PAIR; } and unless ($value) { next PAIR; } mean the same thing?

Or perhaps this would be better:

unless ($value) { next PAIR; }
to
unless ($value && $value != 0) { next PAIR; }

I'll try that.

(All this thinking out loud is giving me a headache)

Thanks,
beetlemanTongue

Marcus L. Griswold
Quote Reply
Re: [beetleman] File Upload 2 Mod killed my zeros. In reply to
Okay, that definitly isn't correct!
beetlemanTongue

Marcus L. Griswold
Quote Reply
Re: [beetleman] File Upload 2 Mod killed my zeros. In reply to
Okay, I'm sorry for all of the extra post, but I really don't understand the use of:
unless ($value) { next PAIR; }
I know that it checks to see if there is a value for the pair, but I don't know why it needs to perform the check!

So, I'm trying to rewrite the statement so it will do the same thing it originally was suppossed to do but still allow zero to be used.

Currently, I just have the statement commented out and everything is working fine. But without understanding what it really does, I don't want to just leave the statement out alltogether.

So I think, that I can circumvent the zero limitation with the following:

unless ($value =~ /\w+/) { next PAIR; }

As this line works fine in the script, I just need to know if it still is doing whatever it was suppossed to do.

Thanks,
beetlemanTongue

Marcus L. Griswold
Quote Reply
Re: [beetleman] File Upload 2 Mod killed my zeros. In reply to
I did a little test by inserting the following code into a default dbman setup, after allowing the Title to be null in the config that is;

Code:
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Title:</FONT></TD>
<TD>&nbsp;<$font>$rec{'Title'}</Font></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Title:</FONT></TD>
<TD>&nbsp;<$font>
|;

# $rec{'Title'}

if ( length ( $rec{'Title'} ) == 0 ) { print qq| if ( length ( rec{'Title'} ) == 0 ) <br> |;}

if ( $rec{'Title'} ) { print qq| if ( rec{'Title'} ) <br> |;}

unless ( length ( $rec{'Title'} ) == 0 ) { print qq| unless ( length ( rec{'Title'} ) == 0 ) <br> |;}

unless ( $rec{'Title'} ) { print qq| unless ( rec{'Title'} ) <br> |;}


print length ( $rec{'Title'} );

print qq|


</Font></TD></TR>

you can see the results and add a null or zero tilte at;

http://www.herbicide-adjuvants.com/...in/db.cgi?db=default

just log in as author / author


In a nutshell;


I think you should replace your
unless ($value) { next PAIR; }
with
unless ( length ($value) ) { next PAIR; }

Keep in mind, the unless is opposite of if, it triggers the action "if" the expression evaluates to false or zero.

yes that can make your head hurt Unsure