Gossamer Forum
Home : Products : DBMan : Installation :

External text mod -- multiple textareas?

Quote Reply
External text mod -- multiple textareas?
I've beaten my head against the wall for three days and nights over this problem, but I can't seem to figure it out. Crazy Maybe one of the more experienced participants in this forum can answer this question (I can't seem to find an answer anywhere on this forum or on the Hypermart site).

Basically, I've incorporated JPDeni's excellent external text upload mod, but now I'd like to be able to save the contents of not just one but three textareas as external text files. Everything works except when I try to modify a record, in which case the textareas don't get populated with any text.

To combine the three textareas, I added the following line to both "sub add_record" and "sub modify_record" in "db.cgi."

$in{'text'} = "$in{'narrative'}\|$in{'teaser'}\|$in{'article'}";

This works great. The $in{'text'} gets written correctly to the external file with pipe delimiters. In order to separate the three fields again for display, I added the following to "html_record" in my .pl file:

open (TEXT, "<$save_text_dir/$rec{$db_key}.txt") or &cgierr("error in displaying record. unable to open text file $save_text_dir/$rec{$db_key}.txt\nReason: $!");
@text = <TEXT>;
close TEXT;
$rec{'text'} = join "",@text;
@Splitter = split /\|/, $rec{'text'}; # Break up the text file into separate values. (The use of @Splitter was intentional.)
$rec{'narrative'} = $Splitter[0];
$rec{'teaser'} = $Splitter[1];
$rec{'article'} = $Splitter[2];


Again, everything diplays correctly.

The only problem is, when I try to modify a record, the three textareas show up as blank. Here's the code I added to "sub html_record_form" in my .pl file:

if ($in{'modify'}) {

open (TEXT, "<$save_text_dir/$rec{$db_key}.txt") or &cgierr("error in html_record_form. Unable to open text file $save_text_dir/$rec{$db_key}.txt\nReason: $!");
@text = <TEXT>;
close TEXT;
$in{'text'} = join "",@text;

@Splitter = split /\|/, $in{'text'};
$Splitter[0] = $in{'narrative'};
$Splitter[1] = $in{'teaser'};
$Splitter[2] = $in{'article'};

}


What could be wrong here? If anyone wants to take a crack at this I would REALLY appreciate it! I've uploaded my files as text files to the following location: http://www.fianchetto.com/dbman

Thanks--Hal
Quote Reply
Re: [Halito] External text mod -- multiple textareas? In reply to
This is a total shot in the dark since I'm just learning this myself...

If textareas coming up blank then notice that you have
$rec{'narrative'} = $Splitter[0]; for display, but you have
$Splitter[0] = $in{'narrative'}; for modify (see how they are reversed?).

Doesn't modify need to read your text file to display the items for modifying?


- Just thought perhaps I could help. If not, I apologize in advance Smile.


Last edited by:

Watts: Oct 9, 2001, 3:51 PM
Quote Reply
Re: [Watts] External text mod -- multiple textareas? In reply to
Thanks for the idea, Watts. I'm just a beginner myself. However, I've found it doesn't seem to matter whether or not these statements are reversed.

The code I posted is the result of a previous try to see if reversing them would make any difference. It didn't. Sigh...
Quote Reply
Re: [Halito] External text mod -- multiple textareas? In reply to
Okay, the only record that doesn't split the text file into separate textareas in the "Modify" screen is the record without an ID number. DBMan numbers all records except the first one, which just gets a blank in the place where the ID number should appear.

For some reason, the external text mod doesn't seem to want to open the corresponding ".txt" file, at least not with this multiple textarea twist I'm throwing into it.

So now my question is, can I force DBMan to give each record a number? Deleting the record without an ID number doesn't help because DBMan then gives the next record you add an ID of none. Alternately, is there a way to get this mod to work even though one record has a blank in place of an ID number?

Any thoughts are greatly appreciated!--Hal

Quote Reply
Re: [Halito] External text mod -- multiple textareas? In reply to
Yeah, check your config (default.cfg)

and create:
'ID' => [ 0, 'alpha', 20, 255, 1, '', ''],

then set
$db_key = 'ID';
$db_key_track = 1;

Try resetting your default.count file also, or bump it up to like 500 or something to eliminate records having duplicate ID #'s.

Sometimes I find it useful to upload an empty default.db file when things have gotten too whacky.

-Good Luck.

Ps: what if you went in an manually numbered the record (and textfile) with an ID like A123 or something?

Post deleted by LoisC In reply to
Quote Reply
Re: [Watts] External text mod -- multiple textareas? In reply to
Day #4:

Setting the ID field to "not-null" results in an error message ("Can't leave ID field blank") every time I try to add a record, even if I've added the <input type="hidden" name="$db_key" value="$rec{'$db_key'}"> tag to sub html_add_form.

In my .cfg file, I have the following set:

$db_key = "ID";
$db_key_track = "1";


I've tried setting the ID key to both alpha and numer, but neither seems to work, no matter which numbers or letter-number combinations I enter into my .count file. In fact, the .count file seems to have no effect whatsoever on the IDs DBMan assigns to records.

I'm still stumped and EVER so frustrated!!--Hal
Quote Reply
Re: [Halito] External text mod -- multiple textareas? In reply to
Thats because this:

<input type="hidden" name="$db_key" value="$rec{'$db_key'}">

...is wrong.

You have $db_key inside ' ' so it will be ignored by perl.

Try

<input type="hidden" name="$db_key" value="$rec{$db_key}">
Quote Reply
Re: [Halito] External text mod -- multiple textareas? In reply to
It doesn't matter whether I use $rec{'$db_key'} or $rec{$db_key} for the value of the hidden ID input field in sub html_add_form. It also makes no difference what I put in the .count file. Every time I delete the record with the blank ID key, DBMan just assigns it to the very next record I create.

It's SO obnoxious! I'm trying to think of a workaround, and here's what I have come up with, though it still doesn't work.

In sub html_record_form, I'm trying to write a nested if statement that checks if the record being modified has a blank ID. If it does, it tries to get the ".txt" file. As I said, this doesn't work, but maybe there is a way to do it. The nested if statement appears in red below:

if ($in{'modify'}) {
if ($db_key eq "") {
open (TEXT, "<$save_text_dir/.txt") or &cgierr("error in html_record_form. Unable to open text file $save_text_dir/.txt\nReason: $!");
@text = <TEXT>;
close TEXT;
}

else { open (TEXT, "<$save_text_dir/$rec{$db_key}.txt") or &cgierr("error in html_record_form. Unable to open text file $save_text_dir/$rec{$db_key}.txt\nReason: $!");
@text = <TEXT>;
close TEXT;
}
$in{'text'} = join "",@text;
@Splitter = split /\|/, $in{'text'};

$in{'narrative'} = $Splitter[0];
$in{'teaser'} = $Splitter[1];
$in{'article'} = $Splitter[2];
}

Quote Reply
Re: [Halito] External text mod -- multiple textareas? In reply to
I finally found a workaround, but it wasn't the nested if statement I tried above. Instead, I set my ID field as follows in default.cfg:

ID => [0, 'alpha', -1, 4, 1, '', '',],

Then, I added the following hidden input field to both the sub html_add_record and sub html_add_failure:

<input type="hidden" name="$db_key" value="a$rec{'$db_key'}">

That way, there's never a ".txt" file created by the external text mod, since the first record created will be called "a.txt." I'm happy now. I think I'll rest for about five hours and try not to dream about DBMan!

--Hal
Quote Reply
HELP please with multi text fields In reply to
after looking thru the above i implemented the multi text field mod from above. Works fine except same problem that Halito had, modifying record brings back nothing in my text fields. I gather that he found the problem but did not post fix. I too have problem with dbman needing a blank ID field in one record, but this definately is not why I am haveing problems. I have renamed my text fields 'text1' text2, text3. I don't think this is having any bearing on my problem though, as I can display appropriate data, except not in modify record??

Thanks
Quote Reply
Re: [flymo] HELP please with multi text fields In reply to
The original post was referring to having all 3 fields saved into the same .txt file. Are you wanting to do the same thing?

I would think that saving them into different directories may help to solve using 3 different fields. Try setting your $save_text_dir to perhaps:

$save1_text_dir
$save2_text_dir
$save3_text_dir

Perhaps that would help?

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [flymo] HELP please with multi text fields In reply to
It's been a while since I have gotten any DBMan dirt under my fingernails, but I'm pretty sure the blank ID definitely is the problem. The script wouldn't display any text when the text file was named .txt. Instead, the file needs to be named something like 001.txt. To solve this, I added 001 in my html_add_form subroutine in html.pl like so...

<input type="hidden" name="$db_key" value="001$rec{'$db_key'}">

This writes your first text file as 001.txt, the next one as 002.txt, then 003.txt, and so forth. You have a maximum of 1,000 files, though, because at number 1,001 the first text file will be overwritten. Of course, you can increase this number by just adding more zeros.

Try this first before anything else, because I'm pretty sure this was the problem. I wish GT would fix this and a few other DBMan bugs someday even though it's not their fanciest product anymore.
Quote Reply
Re: [Halito] HELP please with multi text fields In reply to
thanks 4 all replies....been away 4 couple of days but will now implement the above suggestions.

Re-Halito....i manually renamed id's and coresponding txt file, so i had no blank id. This still had no bearing on the text fields being blank for the modify record page, on any record?? So i don't think my problems are caused by this. I will try everything offered here and get back 2 u.

And sorry Paul, duly noted Frown

Thanks to all.....

Last edited by:

flymo: Aug 29, 2002, 6:38 PM