Gossamer Forum
Home : Products : DBMan : Customization :

Problem with Select & Text name for same field

Quote Reply
Problem with Select & Text name for same field
I am trying to install a mod by Rick Guyer to put a text field beside a select field in case selections are not complete.

In db.cgi after
if ($value eq "---") { next PAIR; }

I added this line

unless ($value) { next PAIR; }

I added this subroutine to db.cgi
sub beside_select_field {
# --------------------------------------------------------
# Used for placing a text box next to a select field. If the $value isn't in the array, then it prints the $value in the text box.

my ($column, $value, $size) = @_;
my (@fields, $ouptut, $tmp);

@fields = split (/\,/, $db_select_fields{$column});
if ($#fields == -1) {
$output = "error building select field: no select fields specified in config for field '$column'!";
}
else {
$output = qq|<input name="$column" size="$size"|;
foreach $field (@fields) {
if ($value eq $field) {
$output .=">";
return $output;
}
else {$tmp=1;}
}
if ($tmp=1) {
$output .=" value=\"$value\">";
}
}
return $output;
}

I added this line to my html_record_form, right after the select field.

print &beside_select_field ("House Type", "$rec{'House Type'}", "$db_form_len{'20'}");

When adding a record, if nothing is selected in the select box but input something into the text box, I encounter this error saying the "House Type (the field name) should not be blank". It seems the input in the text field can not be passed. I double checked my field name and other things to be sure they are correct. Any clue will be greatly appreciated.

Long



Quote Reply
Re: Problem with Select & Text name for same field In reply to
Well I'm not sure if this is the problem, but do you have the field as required in your .cfg file?

Also the thread reference http://gossamer-threads.com/p/002866.html states:

print &beside_select_field ("Trailer", "$rec{'Trailer'}", "$db_form_len{'Trailer'}");

and you have:

print &beside_select_field ("House Type", "$rec{'House Type'}", "$db_form_len{'20'}");

Notice that the $db_form_len{'20'} in your example is showing a number rather than the field name.

I'm not sure if that will make a difference. Also i'm wondering if having a space in the field name is making a difference?

Hopefully JPDeni will be back soon and can help you solve this.



Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
I guess I missed that post originally. I'm not sure what the point of it is.

What do you want to accomplish?




JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
Thanks both to LoisC and JPD!

Reply to LoisC

In this line
print &beside_select_field ("Trailer", "$rec{'Trailer'}", "$db_form_len{'Trailer'}");

I think the last 'Trailer' is actually the variable for form length, so I pass a number to it, I also tried field name, it made no difference. Also one-word field name to replace 'Trailer' made no difference either.

Reply to JPD

Thread reference:
http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/002866.html


This is the subroutine I used

sub beside_select_field {
# --------------------------------------------------------
# Used for placing a text box next to a select field. If the $value isn't in the array, then it prints the $value in the text box.

my ($column, $value, $size) = @_;
my (@fields, $ouptut, $tmp);

@fields = split (/\,/, $db_select_fields{$column});
if ($#fields == -1) {
$output = "error building select field: no select fields specified in config for field '$column'!";
}
else {
$output = qq|<input type="text" name="$column" size="$size"|;
foreach $field (@fields) {
if ($value eq $field) {
$output .=">";
return $output;
}
else {$tmp=1;}
}
if ($tmp=1) {
$output .=" value=\"$value\">";
}
}
return $output;
}
#------------------------

Long



Quote Reply
Re: Problem with Select & Text name for same field In reply to
I understand what your subroutine is, but I'm still not sure how you're using it. Do you also have

print &build_select_field("Trailer", "$rec{'Trailer'}");

in sub html_record_form?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
Yes, I have both as following

print &build_select_field("Trailer", "$rec{'Trailer'}");
print &beside_select_field ("Trailer", "$rec{'Trailer'}", "$db_form_len{'Trailer'}");

I also try this:
print &build_select_field("Trailer", "$rec{'Trailer'}");print qq|<input type="text" name="Trailer" value="$rec{'Trailer'}">|;

If I did not select a value but input something in the text box, it says you can not leave that field blank. I think this is very useful mod, and wish you could help me out.

Long




Quote Reply
Re: Problem with Select & Text name for same field In reply to
But it works when you select something from the select field?

Try taking out the line

unless ($value) { next PAIR; }

from sub parse_form. See if that helps.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
Yes, it works if I select something from the select box.

I took out the line:

unless ($value) { next PAIR; }

It made no difference.

Long



Quote Reply
Re: Problem with Select & Text name for same field In reply to
I'll need you to set [red}$db_debug=1;[/red] in your .cfg file. At the bottom of the page will be a list of the variables. Check to see if there is one for "Trailer."

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
There is no value for that field and even the field name was not listed.

I check the source code, it's OK.

if I put the text box in front of the select box, it works fine. but again, if the text box is blank and select something, no value will be passed. So it seems the program only recognize the first Name/Value pair, if no value for the first Name/Value, it won't look the second Name/Value pair for a value.

this is my sub parse_form

sub parse_form {
# --------------------------------------------------------
my (%in);
my ($buffer, $pair, $name, $value);

PAIR: foreach $name ($query->param()) {
$value = $query->param("$name");
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s///g;
if ($value eq "---") { next PAIR; }
unless ($value) { next PAIR; }
(exists $in{$name}) ?
($in{$name} .= "~~$value") :
($in{$name} = $value);
}
return %in;
}


Long

Quote Reply
Re: Problem with Select & Text name for same field In reply to
Please take out the line

unless ($value) { next PAIR; }

and please don't put it back.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
Hi, JPDeni

Actually, I tried without this line: unless ($value) { next PAIR; }
and found no difference.

Long



Quote Reply
Re: Problem with Select & Text name for same field In reply to
I know that. But don't put it back in. I'm trying to figure out what the problem is and I have to go one step at a time. This has been a problem in the past, so I'm trying to eliminate it.

I'll need you to post sub html_record_form. That's the only possible way to figure out what's going on.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
Hi, JPDeni

Thanks for reply. This is my sub html_record_form. I have not yet added the codes you gave me in another post for importing fields from user db.

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">|;

print &build_select_field("Type",$rec{'Type'});
print &beside_select_field ("Type", "$rec{'Type'}", "$db_form_len{'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></TABLE>|;
}





Quote Reply
Re: Problem with Select & Text name for same field In reply to
Change

print &beside_select_field ("Type", "$rec{'Type'}", "$db_form_len{'Type'}");

to

print qq|<input name="Type" value=$rec{'Type'} MAXLENGTH="20">|;

and see if you get it to print out when you have $db_debug=1.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
Hi, JPDeni

It's still not working, the value in the text box can not be passed. The debug info didn't list the "Type" field name.

Long



Quote Reply
Re: Problem with Select & Text name for same field In reply to
Okay, then. Temporarily remove (or comment out)

print &build_select_field("Type",$rec{'Type'});

so that there is only one input field for that database field. Add a record and see what happens.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
Hi, JPDeni

Without the select box, I can pass data into the db through the text box.

Long

Quote Reply
Re: Problem with Select & Text name for same field In reply to
That just doesn't make any sense to me. The parse_form subroutine is designed to take multiple inputs.

I am completely at a loss as to what could cause your problem.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Problem with Select & Text name for same field In reply to
Hi, JPDeni

If it's absolutely possible for the current dbman script to have two input boxes with the same name and to take the value from the second box if the first is empty, then I will double check my code and do some more experiments with it to find out what's wrong.

Thank you very much for your help.

Long

Quote Reply
Re: Problem with Select & Text name for same field In reply to
It is absolutely possible for DBMan to take input from two form fields that have the same name. It doesn't matter if one is empty or not.

JPD
http://www.jpdeni.com/dbman/