Gossamer Forum
Home : Products : DBMan : Installation :

New Form -

Quote Reply
New Form -
What's the best approach for adding a new form to dbman -- work out a fix in html.pl or modify db.cgi.

Here's what's desired. I want to create a new form which a user will fill out and then the contents of this form will be mailed to a given recipient. I can do all of this in html and bypass dbman altogether except I need the email address from the dbman records.

So when a user clicks on a link, they will be given a screen form to complete and this is emailed to the email field in dbman. I've got everything figured out, tested and so on except getting the email field from dbman into the form. What my question really concerns is should I setup another sub in html.pl like add, modify, etc. or should I use an existing sub and modify it with a flag of some kind. The only field being accessed from dbman is the email field. There is no writing to dbman.

Quote Reply
Re: New Form - In reply to
You can modify an existing sub, but sometimes it gets confusing. After a while it's easy to forget which "if" you're dealing with. My suggestion is to make a new subroutine in html.pl for your form. You probably won't have to do very much to get the email address out of the database. If you pass the key of the record you need when you click the link, all you have to do is put

%rec = &get_record($in{$db_key});

at the beginning of your new subroutine.

The only other thing you'll need to do is to have a "switch" in sub main in db.cgi.

elsif (whatever) { &html_whatever; }



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





Quote Reply
Re: New Form - In reply to
OK, thanks -- basically things are working fine except for the parsing of the email field I want.
Here's what I've done.
1. db.cgi -- added elsif stuff to handle new sub -- this works fine.
2. Put 2 new subs into html.pl : a. sub html_reservations_form -- this has all the html for the new form -- similar in concept to the sub html_record_long. b. sub html_reservations -- this sub is as follows:

sub html_reservations {
#--------------------------------------------------------
# Form for inn reservations to be emailed to innkeepers

%rec = &get_record($in{$db_key});

# < -- Start page text -- >
print qq|
|;
&html_reservations_form(%rec);

}

Here is how I call the sub html_reservations from my program.

I'm using your short/long mod -- First I search by State -- a list of ten items in a given state are returned. I then can click on a link to see the detailed record as per your mod example. What I've also setup is another link which when clicked on should generate the reservation form (which it does) but it doesn't pass the value of my email field to the newly displayed form.

Here's my call:
<A href="$db_script_link_url&ww=on&$db_key=$rec{$db_key}&reservations=1"><IMG
alt=Reservations border=0 height=15
src="../../../reservations.gif"
vspace=2 width=90></A?>

As I stated -- this works, it brings up the new reservation form in sub html_reservations which in turn calls html_reservations_form. It just doesn't fill the $rec{'Email'} field with the value of the email address of the selected record.
Quote Reply
Re: New Form - In reply to
It's possible that you left off one line of your html_reservations_form subroutine. (I did this at the beginning and had a heck of a time figuring out why it wouldn't work.) Check to see that the first line of sub html_reservations_form is

my (%rec) = @_;

If that doesn't fix it, you'll need to do some debugging. In sub html_reservations, after

# < -- Start page text -- >
print qq|

add

$rec{'Email'}

This will show you whether the record was found in the first place. If not, then we'll have some other looking to figure out why not.


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





Quote Reply
Re: New Form - In reply to
Doesn't work -- I put the debug code in and it is empty -- nada!

I've gone back through things and just can see why the record is being passed to that routine.

Perhaps you can peruse my source and give some ideas -- just search for reservations in the html.pl.txt file and you'll find the two subs in html.pl

The reservations sub is called from a javascript function -- the actual code for the call is in the sub html_top where you'll find a javascript function named GoAvail.

The source can be looked at by going to:

http://192.41.11.48/html.pl.txt

I'll apppreciate your insight -- I didn't upload the db.cgi file because it does find and process the new form correctly.
Quote Reply
Re: New Form - In reply to
I found your problem. It's because you're using the Javascript in html_page_top, before the %rec array is defined.

I'm not sure you can use Javascript for this. You need the Javascript code to change with each record in order to pass the $rec{$db_key} to the reservations subroutine. I don't know enough about Javascript to help you, except that I think there is a way to pass a value to the script at the time of execution. How it works, I have no idea. Smile

At least I can tell you why it doesn't work, even if I can't tell you how to make it work.

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





Quote Reply
Re: New Form - In reply to
Your comments make sense for repetitive calls using the javascript -- the placement of the javascript, however, is not the problem!!

I've coded the call directly without using Javascript and it still doesn't work.

You can look at the source as before -- I've made the changes and it still doesn't pass the value at all.
Quote Reply
Re: New Form - In reply to
Thanks for your efforts in trying to tract down the problem -- still doesn't work -- we can both ponder for a while and see what develops!

Another question: is there anyway to do a nested search? For example, I want to do a search based on one boolean criterion and then alphabetically within the criterion.
For example: The criterion is Paid Not Paid.
I want a list of all those who have paid and those who have not paid alphabetically.
What do you think?
Quote Reply
Re: New Form - In reply to
OK, the 2nd line appears with the passed value, the 1st line for record key is blank.

BTW, I didn't upload the txt file previously for you but had made the change and uploaded to my cgi directory. Anyway, the txt file is available for viewing.
Quote Reply
Re: New Form - In reply to
That means the problem is with this line:

%rec = &get_record($in{$db_key});

Try

my (%rec) = &get_record($in{$db_key});

You aren't having any trouble with the data being displayed after you add a record, are you? Or when you modify a record? (I'm thinking of the other times when &get_record is used.)

There are only three elements to that line:

%rec

&get_record

$in{$db_key}

We know that the third element is okay. I don't think it will change anything to add the "my," but it might. If it doesn't, the only thing we're left with is &get_record. And if it works the other times it's used, I'm completely baffled.

Well, I'm going to bed. Maybe I'll dream of a solution. Smile



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





Quote Reply
Re: New Form - In reply to
Did you copy the new html.pl script to the website? The script I see still has

Code:
<TD><A href="javascript:GoAvail()"><IMG
alt=Reservations border=0 height=15
src="../../../reservations.gif"
vspace=2 width=90></A></TD>

Just for debugging purposes, try changing the above to

Code:
<TD>
<a href="$db_script_link_url&$db_key=$rec{$db_key}&reservations=1">
Reservations</a></td>

{BTW, you don't need the "ww=on" in this link.)

If that's what you did, then you'll need to do some other debugging.

In sub html_reservations, change

Code:
# < -- Start page text -- >
print qq|
$rec{'Email'} $rec{'ID'}
|;

to

Code:
# < -- Start page text -- >
print qq|
record key = $rec{$db_key}<BR>
passed value = $in{$db_key}
|;

You should end up with the same value on both lines. If you get the second line, but not the first, then for some reason (which we'll try to find) the record isn't being found in the database. If you don't get either value, then the $db_key is not being passed to the script via the link. If you get both of them, there's some other problem which we'll try to find.


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





Quote Reply
Re: New Form - In reply to
I don't know if you can do a nested search or not and I really don't want to pursue anything new with you until we get this worked out.

Did you check to be sure that your html_add_success, html_modify_form_record and html_modify_success subroutines work correctly? Do they print out the record?



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





Quote Reply
Re: New Form - In reply to
Yes, all the routines mentioned work fine and print out the record.
Quote Reply
Re: New Form - In reply to
In further experimenting -- I used modify_form_record as a surrogate for reservations -- changed the calls and did some printing -- the value of db_key is being passed but not the record. Same problem we were having with the reservations --

Just a though -- do we need to modify the db.cgi program to have another search of the db? It seems like your approach should work -- it's logical and works with the detailed search output. Is there another way to pass the rec to the sub other than pass the key to the record?
Quote Reply
Re: New Form - In reply to
There's one more debugging thing we can try.

In your subroutine, instead of

%rec = &get_record($in{$db_key});

find the key of a record that you know exists. For example, if you have a record with the key of "74," use

%rec = &get_record("74");

Then print out

$rec{'ID'}

This will let us know if there's some problem with &get_record. (I don't know what we'll do with that information, but at least we'll have it. Smile )

I don't know of another way to pass the record without using the key.



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





Quote Reply
Re: New Form - In reply to
Don't think it's the database -- the database is live, over 3700 entries, online everyday and is working fine.
Updates are made daily, new records added daily, deletes, modications and so on -- no problemos whatsoverver!!

The only problem is this one routine!
Quote Reply
Re: New Form - In reply to
Printing the $rec{'ID'} yields nothing -- just blank.

Soooooo............!
Quote Reply
Re: New Form - In reply to
Then it appears there is something wrong with your database. I can't figure out anything else. Possibly it became corrupted for some reason or you added or deleted fields after you had the records in the database.



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





Quote Reply
Re: New Form - In reply to
Well, I'm all out of ideas. Long-distance debugging at this point is pretty difficult.



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





Quote Reply
Re: New Form - In reply to
Whatever works!! Smile

Glad you got it to do what you wanted.


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





Quote Reply
Re: New Form - In reply to
I figured out a fix which works great -- don't know why the way we were trying didn't work but here's a simple solution which works fine.

I used the html_view_success routine and have the following code:
if ($in{'reservations'}) {
$page_title = "Reservation Form";
$banner = "Reservation_Request_Scherzo_BannerH.gif";
&html_page_top;
&html_reservations_form(&array_to_hash(0, @hits));
&html_page_bottom;
return; }

In the db.cgi file I changed the elsif to

elsif ($in{'reservations'}) { &view_records; }

The call from my sub record_html is
<A href="$db_script_link_url<A href="$db_script_link_url&$db_key=$rec{$db_key}&reservations=1"> other stuff goes here.

I probably don't need the db_key stuff immediately above but every thing is working great now.

I appreciate all the time and effort you spent trying to help debug -- but it's working now -- it's great!