Gossamer Forum
Home : General : Perl Programming :

How to: Allow double quotes in form field?

Quote Reply
How to: Allow double quotes in form field?
I posted this to question to the DBMan discussion forum last week and didn't get an answer. So, I thought I would give this forum a try.

I use DBMan for a news headline database. Double quotes are often used in headlines, and can appear at any place in the string.

In DBMan the add_record subroutine works fine and the double quotes in (Choosing the "Right" PC) are saved to the database. However, when or if the record is modified all data in the field after the first double quote is stripped.

I am not sure what to modify. I think it's in one of these subs?

############ get_record #################
# ...snip

LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
next LINE if ($restricted and ($db_userid ne $data[$auth_user_field]));
if ($data[$db_key_pos] eq $key) {
$found = 1;
for ($i = 0; $i <= $#db_cols; $i++) {
$rec{$db_cols[$i]} = $data[$i];
}
last LINE;
}
}

# snip...

##############################
sub split_decode {

my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o;
my (@array) = split (/\Q$db_delim\E/o, $input);
for ($i = 0; $i <= $#array; $i++) {
$array[$i] =~ s/~~/$db_delim/og;
$array[$i] =~ s/``/\n/g;
}
return @array;
}

I have checked perllop, Perl 5 by Example, and searched these forums to no avail. Any help will be greatly appreciated.

------------------
Larry "NgtCrwlr" Mingus
www.makeitsimple.com

Quote Reply
Re: How to: Allow double quotes in form field? In reply to
It appears that they are not actually using " but ``.

It seems that in the sub split_decode, this regex converts `` to a new line.
Code:
$array[$i] =~ s/``/\n/g;
Try converting the `` to " before adding to the DB.

In db.cgi in the sub add_record before:
Code:
if ($status eq "ok") {
Add this:
Code:
$in{'headline_or_name_of_field'} = s/``/"/g;

chris@wfmy.com

------------------
WFMY-TV Webmaster

[This message has been edited by Chris071371 (edited November 07, 1999).]
Quote Reply
Re: How to: Allow double quotes in form field? In reply to
Hi Chris,

I think the split_decode line that you refer to is putting back in the line feeds that are stripped when the data is saved to the data file. From what I understand line feed/carriage returns are converted to a pair of (' ') for each line feed. I don’t' think that line has anything to do with double quotes?

I finally got this question answered in the DBMan Discussion forum. Dave T came up with a rather interesting workaround, I can't explain why it works but this fixed the problem for one of my fields.

Quote:
<input type="text"
Try Value='$rec{"Headline"}'
Not Value="$rec{'Headline'}"
Turn your quotes inside out on this one.
It worked for me with Netscape 4.01, IE 4.xx
But now you can`t use ' without stripping after.
Dave T

Now that I read this again I have to check something. I am wondering if a single (') as in (it's) will now cause a problem? Hmmm… I didn't catch this the other day, back to the drawing board I guess.

Cheers!

------------------
Larry "NgtCrwlr" Mingus
www.makeitsimple.com

[This message has been edited by NgtCrwlr (edited November 06, 1999).]
Quote Reply
Re: How to: Allow double quotes in form field? In reply to
If you will just try the solution I posted above, I guarantee it will work!

------------------
WFMY-TV Webmaster