Gossamer Forum
Home : Products : DBMan : Installation :

Can I use Multiple forms?

Quote Reply
Can I use Multiple forms?
Is it possible to allow a user to first create a record by using a main form, and then allow them to later use another (much reduced) form to update it? Here's what I'm getting at:

The user fills out his profile with all the essential info on my main form. On it he specifies what music he likes as well as any particular CD's he is looking for (this is a local Album/CD Exchange Users Group). So say he selects Nat King Cole as an artist he likes. If he is looking to trade for CDs he doesn't have he can check the "Active" checkbox by Nat King Cole. If he doesn't want to do trades on that artist he checks the "Inactive." I would like for the users to just be able to pop up a list of their music preferences and select whether an artist is active or inactive without pulling up all their other user info, but yet still write it back to the same db so that when other users search their record the updated preference is shown. I've tried hacking around at a sub rouutine, but since I am not a perl expert I think I'm way off!

Can anyone point me in the right direction?

Thanks!
Quote Reply
Re: Can I use Multiple forms? In reply to
Yep. You can create another subroutine for modifying.

Copy sub html_record_form and paste it below the current one. You will now have two identical subroutines. Rename the second one to sub html_modify_form.

For every one of the fields you do not want the user to modify, change it to a hidden field.

For example, let's say this is your current html_record_form:

Code:
print qq|
<table>
<tr><td>ID:</td>
<td><input type="text" name="ID" value="$rec{'ID'}"></td></tr>
<tr><td>Name:</td>
<td><input type="text" name="Name" value="$rec{'Name'}"></td></tr>
<tr><td>Favorite Color:</td>
<td><input type="text" name="Color" value="$rec{'Color'}"></td></tr>
</table>
|;

You only want users to be able to change the "Favorite Color" field.

Code:
print qq|
<table>
<input type="hidden" name="ID" value="$rec{'ID'}">
<input type="hidden" name="Name" value="$rec{'Name'}">
<tr><td>Favorite Color:</td>
<td><input type="text" name="Color" value="$rec{'Color'}"></td></tr>
</table>
|;

Then go down to sub html_modify_form_record and change

&html_record_form

to

&html_modify_form



------------------
JPD







[This message has been edited by JPDeni (edited August 29, 1999).]
Quote Reply
Re: Can I use Multiple forms? In reply to
JPDeni -

Thanks for helping me figure that one out. Worked just great!

In the process, I figured out that I have one other twist to this that I didn't think of. My original questioned assumed that all the people in the users group would have a thier favorite music listed in one record, but how can I do exactly what you showed me from multiple records? Here's what I mean:

Say guy #1 creates a record with his favorite music under the Swing category, but then also creates another record in the Blues category (all same database, just different records). In both records he wants selects certain albums/CDs he's looking for. Just as I was able to pop up just the info I wanted in your sub html_modify_form, how do I do it if I'm not sure how many records he will have?

The sub html_modify_form allowed me to hard code which fields that I want to show up in the smaller form, which works perfect if, like in your example, I just want to allow the color field to be modified. But what if I want the color field from ALL his records to be shown on the form?

How this would look would be very basic. In fact, it would look kinda like a Short Record. It would show the all the music CDs he wants (the title of each one) and then just have a two radio buttons (for Active or Inactive -- i.e. looking or not looking) by each title. So I guess what I'm trying to do is create a similar display as the short record that would grab all his stuff from all his records and then put radio buttons by each one, then after he makes the update it goes back and updates the db so that users know his status.

Your first solution worked so great and I was so pumped up! If you have ideas on this twist I sure would appreciate it too...

Thanks!
Quote Reply
Re: Can I use Multiple forms? In reply to
Let me make sure I understand this.

Each user might have multiple records, each dealing with a different kind of music. In each record, the user has a list of CDs he wants. He then states whether the list is "Active" or "Inactive." The whole list.

So, if I registered on your database, I might have a record where I say I want "Oldies." And then I list

"With the Beatles"
"Abby Road"
"Let It Be"

in my list of wanted CDs. This would all be in one record.

I also have a record where I list my "Classical" wish list, which would include

"Julian Bream -- The Woods So Wild"
"Andre Segovia -- Greatest Hits"

Have I got it right so far?

What happens when I get a copy of "The Woods So Wild" and "Abbey Road"? I would still be looking for "With the Beatles" and the Segovia.

Or does the user create a record for every CD he wants, which would mean that I would have created 5 records?

It really makes a difference in the coding for me to understand your setup. Smile

Also, would the "Active/Inactive" field be the only thing the user could modify?


------------------
JPD





Quote Reply
Re: Can I use Multiple forms? In reply to
Hey anything wild and crazy works for me!

You're the master at this stuff, if you have a brainstorm then by all means I would LOVE to see the results!

Your diagram is exactly what I'm thinkng, so if you think the way your idea will achieve just disregard how I was invisioning it --

Thanks JPDeni!

Quote Reply
Re: Can I use Multiple forms? In reply to
(My choice of which types of music to use as examples was based on the CDs that are sitting next to my computer, and by your handle. Smile ) It wouldn't be too hard to connect the two, using the userid and would make this whole thing a lot easier.

It's a little tricky to set up, but once it's done it would be very slick.


------------------
JPD





Quote Reply
Re: Can I use Multiple forms? In reply to
Hey JPDeni....you have great taste in music!

And yes, you are very close to the idea. When a user creates a record under a category, he can list up to 6 artists and up to 6 albums/cd's per artist (btw, I didn't have this completely figured out before... But you actually gave me some brain food in your reply back that helped me nail it down! Thanks!). So Guy #1 likes the Beatles - he can list 6 albums/CDs he is looking for or wanting to trade. That would all be a single line in the db. He could do the same in Classical, Jazz and Country, which would all be new records...in the same db. So, when Guy #2 is trying to find someone to swap Beatles albums with, he finds Guy #1's record and sees his trading list. If Guy #1 is already talking with say, Guy #3 about one of the albums, he (guy #1) would be able to "inactivate" the album by checking the Inactive radio button. He might choose to do this if this particular album is known to generate alot of responses and he doensn't want to be bothered while he's trying to work it our with Guy #3. If he can't reach a good trade with Guy #3, he could then go back and "Activate" the album again, or if he did make a swap and no longer wants the album listed, he could go back to the full record and delete it from his list altogether. It would actually be REALLY cool if there were a way to have a checkbox to delete and Modify by each Title displayed in the sub html_modify_form too! Then he could do it all from there! That would be excellent!

Otherwise, just displaying each of his CD titles with an Activate and an Inactivate radio button would work.

Does this help? I hope! I'll clarify further if necessary...

Thanks!
Quote Reply
Re: Can I use Multiple forms? In reply to
Okay. Here we go on a new adventure.

Set up two databases -- one for the user information and one for the CD information. There will be no CD info in the "user" db and one CD per record in the "CD" db.

Use the "userid" field in the user"db for the $db_key. Use a counter for the $db_key in the CD db. Also, make sure you have a userid field in the CD db. It would make life much easier if they have the same name.

Once you get the databases set up, let me know. Have you seen my "Configurator"? It might make things a little easier for you. It's at http://www.jpdeni.com/dbman/config.html .


------------------
JPD





Quote Reply
Re: Can I use Multiple forms? In reply to
Hey JPDeni! That is one groovy thing you have there, that configuator! Works like a charm! No doubt about it...you ARE the db goddess!

OK....got a db for the user info called traders.db and got another for the CDs called cd.db (btw, try saying cd.db real fast 10 times!) Smile

Userid and counter are set...What next?

Quote Reply
Re: Can I use Multiple forms? In reply to
Lemme tell you -- that configurator has saved me answering a whole lot of the same questions over and over on the forum -- and it's only been available about a week! Smile

Okay, here's where we get sneaky. (I love getting sneaky. Wink ) I need you to create a couple of subroutines within the db.cgi file. They will be like this:

Code:
sub switch_to_CD {
#-------------------------
@db_cols = (a list of all the fields in your CD database separated by spaces);
$db_file_name = $db_script_path . "/cd.db";
}

sub switch_to_traders {
#-------------------------
@db_cols = (a list of all the fields in your trader database separated by spaces);
$db_file_name = $db_script_path . "/traders.db";
}

You need to be sure of several things --
-- that each of the @db_cols = ... and $db_file_name = ... lines ends with a semi-colon.
-- that you have a { after the line that starts with "sub" and a } at the end of the subroutine
-- that you have a space between each of the field names
-- that, if you have a two-word field name, you enclose it in single quotes -- 'First Name'

Go ahead and add those subroutines. You aren't using them yet, but run your script just to be sure you don't have any syntax errors before we go on.


------------------
JPD





Quote Reply
Re: Can I use Multiple forms? In reply to
....it does feel exciting doing some sneaky stuff here!

I'm with you so far....you lead the way!
Quote Reply
Re: Can I use Multiple forms? In reply to
Okay. Now we're getting to the nitty-gritty.

You have your sub html_record all done for your "traders" html.pl file, right? (If not, do that before you go on.)

At the end of the subroutine, we're gonna list out the CDs that this guy has added to the database. Ready?

Add the following code:

Code:
$in{$db_key} = $db_userid;
# Since the userid is the key for the trader database, and the CD database has a field with
# the same name, we can take advantage of that

$in{'mh'} = 100;
# This will pretty much guarantee we get all the CDs someone has added. You don't want
# to have links to other pages for more CDs

&switch_to_CD;
my ($status2,@hits2) = &query{'view'};
if ($status2 eq 'ok') {
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);
for (0 .. $numhits2 - 1) {
%rec2 = &array_to_hash($_, @hits);

# the next code will be a listing of the information for the CDs.
# You can just copy the code from sub html_record in the cd html.pl file
# and put it here.
#
# Just be sure to use $rec2{'fieldname'} instead of $rec{'fieldname'}.

}
}

&switch_to_traders;

Now, we still don't have your form for "Active" "Inactive" and "Delete" but that's coming. Right now we want to be sure that the switching is working correctly.

What should happen after you get the above code installed is that, below the "trader's" info, the CDs he/she has added will be listed.

(Be sure to read all the comment lines I put in above. Some are explanations and some are instructions. You can take them out after you get the code installed.)


------------------
JPD

PS I gotta go to bed now, so I'll continue this tomorrow.

I realized that I may not have been completely clear in what I wrote above. When you copy the code from the cd html.pl file, just copy the code from the first print qq| command to the last |; in the subroutine. And don't forget to change $rec to $rec2!






[This message has been edited by JPDeni (edited August 31, 1999).]
Quote Reply
Re: Can I use Multiple forms? In reply to
JPDeni! Just got back home from a conference that was almost as much fun as perming your mustache! Smile

I'm excited to see that this wild and crazy adventure continues on -- I am going to go get down to business right now and put this next batch of code together...

Thanks!
Quote Reply
Re: Can I use Multiple forms? In reply to
I'm afraid I have to go to bed. My poor ol' eyes are having a hard time staying open.

I'll be back on as early as I can when I get up to see if there's anything that I can do to help.


------------------
JPD





Quote Reply
Re: Can I use Multiple forms? In reply to
Is there any particular spot you suggest inserting this chunk of code? Should it be with the sub html_record stuff? And how will what your doing be afftected if I am using the short vs long display stuff.....sholud I be using a long display for the CD db? I know were creating a new "layout" for the traders db --- just wnating to make sure I'm on the same page as you before the wild and crazy stuff blasts off!

BTW, to keep from getting a server error on the previous chunk of code I had to put pipes between my db fields instead of spaces. Any thoughts on that one?!

Thanks!
Quote Reply
Re: Can I use Multiple forms? In reply to
This would go in the html_record (or html_record_long) for the traders database. The code that you would use to list the CDs would be the same as what you have in html_record (not html_record_long) from the CD html pl file, because you really just want to print out the titles here.

(Oooh. That's not very clear. If it's as clear as mud for you, let me know and I'll try to explain a little better.)

You can use the short/long display for the CD file. No problem at all.

I'm glad you mentioned it, though, because I've started on your "Active/Inactive/Delete" form and I wasn't sure what format of subroutine I needed to make for the html file. Now I know! Smile

I'm not sure why you would get a server error when using a space as a delimiter, unless it's that it would cause the script to do a lot of work. See, if the script runs across the delimiter within the value of a field, it has to change it so the script will know where one field ends and the other begins.

Let me give you an example.

Let's say a record consists of the following values:

The Beatles
Abbey Road
Oldies but Goodies

In order to set up these values to be saved in the database with a space as a delimter, the script has to change it to:

The~~Beatles Abbey~~Road Oldies~~but~~Goodies

If you're likely to have a lot of spaces, it's probably not a good idea.

The pipe is probably the best for a delimiter, since it's used so rarely.

------------------
JPD





Quote Reply
Re: Can I use Multiple forms? In reply to
JPDeni!

OK>>>>being a guy, I say to myself, you can keep trying to slide this chunk of code in because you're not an idiot....so then the sane side of me kicks in and says, Yeah right...like after 2 days and you still can't figure it out you're gonna somehow get it now! (these are furocious talks my "selfs" have!)

So, I'm hoping you can shed a little more light here. I was with you all the way until this part. Are you saying that I copy the above chunk of code into my sub html_record long or short? And am I supposed to copy my sub html_record from my CD db in my traders.db? (I've tried 'em all! btw SmileObviously just not the right one....)

I hate to ask, but can you run this part by me one more time?

Thanks!

Quote Reply
Re: Can I use Multiple forms? In reply to
Whoops!

[This message has been edited by liverpool (edited September 11, 1999).]
Quote Reply
Re: Can I use Multiple forms? In reply to
I'm really sorry, but I'm going to have to put you off for a bit. I'm really not feeling well and I gotta go back to bed. I'll get back to you as soon as I possibly can.


------------------
JPD





Quote Reply
Re: Can I use Multiple forms? In reply to
Well JPDeni....it only took me 2 weeks, but I finally managed to sort out what it was that was blocking my brain cells from understanding how to setup the last part of the mod. All I can say is that I have my priest AND my travel agent praying for your good health to be restored so I can someday hope to figure out what the next step in this awesome mod is!! Smile

Man...losing JPDeni is worst than losing your wife!