Gossamer Forum
Home : Products : DBMan : Customization :

samll problem with import field between dbs

Quote Reply
samll problem with import field between dbs
I am sure this should not be a problem, but somehow I got stucked with it.

I need to autofill the email field in my item db add_form with the email field in the user db. It's been made quite clear by JPD in her Relational mod and is implemented in sub html_record_long with the following codes:

my (%rec) = @_;
&switch_to_user;
$rec{'UserID'} =~ s/<.?B>//g;
%rec2 = &get_record($rec{'UserID'});
&switch_to_item;

For display, using: $rec2{'UserEmail'}", It works fine in sub html_record_long.

However, when I copied these codes to sub html_record_form, it does not work! The email address never shows up. I could not figure out what's wrong. Could somebody point out to me. Thanks in advance.

Long

Quote Reply
Re: samll problem with import field between dbs In reply to
Taken from the following thread reference:
http://gossamer-threads.com/p/8254


Question:

Using The relational Database of DJ deni users and Items.
Holding customers details in users database and their Items for sale in Items Database.

How is it possible to search as a default users, for an item by county.
The county (location) details being stored in the users database.

how would I pass the county field from the users db to the items db, when a new user signs up.
----------------------------------------------------------
Response:

It isn't possible to search for records across two databases.

In reply to:
how would I pass the county field from the users db to the items db, when a new user signs up

First, add a field to your items database for the county.

At the beginning of sub html_record_form for the items database, after:

my (%rec) = @_;

add:

if ($in{'add_form'} {
&switch_to_users;
$rec2=&get_record($db_userid);
&switch_to_items;
$rec{'County'} = $rec2{'County'};
}

Hope this example answers your question.


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: samll problem with import field between dbs In reply to
Thanks, LoisC

It works great. So the secret is to put this

&switch_to_users;
$rec2=&get_record($db_userid);
&switch_to_items;

within the
if ($in{'add_form'} {

{

Thanks again

Long


Quote Reply
Re: samll problem with import field between dbs In reply to
Hi, LoisC

I found a new problem.

This works fine when adding record, however, in add_failure, modify record, the fields I imported from user db no longer exist! I know all these subrountine call html_recrod_form, why it only works in add_form? should I need to add something in add_failure, html_modify sub?

Best regards,

Long

Quote Reply
Re: samll problem with import field between dbs In reply to
If you have form fields for the information from the other database, it will be saved in your record, so you won't have to worry about it.

If you don't have form fields (for some reason), add $in{'add_form'}=1; to the beginning of the subroutines you mentioned.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: samll problem with import field between dbs In reply to
Thanks, JPD

I have email and user name fields in my item db. Importing those fields from user db works fine only in add_form, in add_failure and also in modify_form those fields no longer have contents in them.

I have attached the add_form sub and add_failure sub for you to check if anything is wrong

sub html_add_form
#----------------------------------
$form_upload = 1;
$page_title = "Add record";
$html_title="For rent";
&html_page_top;

$submit_button = "Preview Record";
$reset_button = "Reset";

# < -- Start page text -- >
print qq|<table width=600 align=center cellspacing=1 bgcolor=#006699>|;
# < -- End page text -->
print qq| <FORM name="Form1" ENCTYPE="multipart/form-data" action="$db_script_url" method="POST">

<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">|;

&html_record_form (&get_defaults);

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="add_record" VALUE="Submit"> 
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>|;
&html_footer_forrent;
&html_page_bottom;
}

sub html_add_failure
#---------------------
$form_upload = 1;
my ($message) = $_[0];

$page_title = "Add failure";
$html_title="For Rent";
&html_page_title;

$submit_button = "Preview Record";
$reset_button = "Reset";

# < -- Start page text -- >
print qq|<table width=600 align=center bgcolor=006699 cellspacing=1><tr><td colspan=2 bgcolor=#d9d9d9>
<FONT COLOR="red"><B>$message</B></FONT></td></tr>|;
# < -- End page text -->
print qq|

<FORM ENCTYPE="multipart/form-data" action="$db_script_url" name=Form1 method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">|;

&html_record_form (%in);

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="add_record" VALUE="Submit"> 
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>|;

&html_footer_forrent;
&html_page_bottom;
}

Quote Reply
Re: samll problem with import field between dbs In reply to
The question is, what do you have in sub html_form_record?

If you have form fields for the userid and email within sub html_form_record, there is no need to pull the information from the other database again, either in sub html_add_failure or in sub html_modify_whatever. The values will have been saved already.

Do you have form fields for the userid and email within sub html_form_record?


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: samll problem with import field between dbs In reply to
Hi, JPDeni

Thanks for reply.

I have 'Conatact Name' and 'Email' field in my item db (also have hidden UserID field). I want to give users a chance to use the default values from user db or use different values for those two fields. So I import UserName and UserEmail from user db into a text box in the add_form of item db, users can import a new value or just let it be. If something goes wrong addig records, which bring up the add_failure sub, however, in add_failure form, the values imported from user db disappeared. If I ignore this problem and submit again, it will say there are no values in those two fields. This happens also with modify_form. I hope I have made it clear. Forgive me for my bad English.


Long

Quote Reply
Re: samll problem with import field between dbs In reply to
What do the fields look like in sub html_record_form? I know this is where your problem is.

Can you please post your sub html_record_form? I will probably be able to solve the problem in a few seconds if I can see the subroutine.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: samll problem with import field between dbs In reply to
sub html_record_form {
# --------------------------------------------------------
my (%rec) = @_;
($db_auto_generate and print &build_html_record_form(%rec) and return);
if ($in{'add_form'}) {
unless ($rec{'UserID'}) {
$rec{'UserID'} = $db_userid;
}
&switch_to_user;
%rec2=&get_record($rec{'UserID'});
&switch_to_joboffer;
}
print qq|<input type="hidden" NAME="ItemID" VALUE="$rec{'ItemID'}">
<input type="hidden" NAME="UserID" VALUE="$rec{'UserID'}">
<TR><TD $td_color ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_red>Ad Title:</FONT></TD>
<TD $td_color VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="Ad Title" SIZE="40" VALUE="$rec{'Ad Title'}" MAXLENGTH="255"></TD></TR>
<TR><TD $td_color ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_red>Type:</FONT></TD>
<TD $td_color VALIGN="TOP" WIDTH="475"> <$font_color>|; print &build_radio_field("Ad Type",$rec{'Ad Type'}); print qq|</font></TD></TR>
<TR><TD $td_color ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_red>Description:</FONT></TD>
<TD $td_color VALIGN="TOP" WIDTH="475"> <TEXTAREA NAME="Description" ROWS="5" COLS="40" WRAP="VIRTUAL" MAXLENGTH="1000">$rec{'Description'}</TEXTAREA></TD></TR>
<TR><TD $td_color ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_red>Your Name:</FONT></TD>

<TD $td_color VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="Your Name" SIZE="20" VALUE="$rec2{'UserFirstName'} $rec2{'UserLastName'}" MAXLENGTH="15"></TD></TR>
<TR><TD $td_color ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Phone:</FONT></TD>
<TD $td_color VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="Day Phone" SIZE="20" VALUE="$rec{'DayPhone'}" MAXLENGTH="15"></TD></TR>
<TR><TD $td_color ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Email:</FONT></TD>

<TD $td_color VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="Email" SIZE="20" VALUE="$rec2{'UserEmail'}" MAXLENGTH="40"></TD></TR>|;
# to close off any previous print qq| statement
if ($per_admin) {
print qq|<tr><td $td_color ALIGN="Right" VALIGN="TOP" WIDTH="150"> Validated</td>
<td $td_color VALIGN="TOP" WIDTH="475"> |; print &build_radio_field($db_validated_field,$rec{$db_validated_field});
print "</td></tr>";
}
else {
print qq|<input type="hidden" name="$db_validated_field" value="$rec{$db_validated_field}">|;
}
print qq|
</TABLE>
|;

}

Quote Reply
Re: samll problem with import field between dbs In reply to
Code:

if ($in{'add_form'}) {
unless ($rec{'UserID'}) {
$rec{'UserID'} = $db_userid;
}
&switch_to_user;
%rec2=&get_record($rec{'UserID'});
&switch_to_joboffer;
$rec{'Your Name'} ="$rec2{'UserFirstName'} $rec2{'UserLastName'}";
$rec{'Email'} = $rec2{'UserEmail'};

}
---------------------------

Code:

<TD $td_color VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="Your Name" SIZE="20"
VALUE="$rec{'Your Name'}" MAXLENGTH="15"></TD></TR>
----------------------------

Code:

<TR><TD $td_color ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font_color>Email:</FONT></TD>
<TD $td_color VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="Email" SIZE="20"
VALUE="$rec{Email'}" MAXLENGTH="40"></TD></TR>|;

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: samll problem with import field between dbs In reply to
Hi, JPDeni

Now it works perfectly. Your are great!

Thank you so much

Long