Gossamer Forum
Home : Products : DBMan : Customization :

'The %20 Situation'

Quote Reply
'The %20 Situation'
Hello all,

I have a database which contains names of people which is being shown one by one, page by page. I also want to make the name fields clickable so that we can figure out if that user name has been exsisting also on other pages (or not).

Maybe by pasting the code will be more helpful for all of us. Here is my line on the page:

<a HreF="/cgi-bin/dbman/db.cgi?db=list&keyword=$rec{'user_name'}&view_records=View+Records">$rec{'user_name'}</a>

Now, let say the user_name at that time is John. Then this script writes the name on the page and links it to a search which will be made against all fields (that's why used as 'keyword')

It's ok for John; BUT...

When the name is John Doe, the link should be written as John%20Doe for the href code (Yes, %20 for space).

Internet Explorer takes cares about it but Netscape does not change nothing. So when you click the link on IE, it lists the records which has the name 'John Doe' but Netscape returns an error page with title 'UNKNOWN ACTION!'

Any ideas? I've fought with it for 2 hours but couldn't get over... I know, it would be better if I could gave the URL but I'm building offline yet.

Thanks everyone.

Quote Reply
Re: 'The %20 Situation' In reply to
Actually, the space should be written as a +.

John+Doe

Just before you print your url, do this;

$user_name = ($rec{'user_name'} =~ s/\s*/\+/g);

<a HreF="/cgi-bin/dbman/db.cgi?db=list&keyword=$user_name&view_records=View+Records">$rec{'user_name'}</a>



[This message has been edited by Chris071371 (edited December 16, 1999).]
Quote Reply
Re: 'The %20 Situation' In reply to
There may be an easy answer to this but you could try this... Don't make the clickable name filed the same as the name field make it another field. then when adding or modifying a record change the db.cgi script so that it takes the name field information "John Doe" and copies it (and also applies a reg expression to it that places %20 in the spaces)to the clickable field. See the code below and compare it to the same sub in your db.cgi - you will see how to automaticaly copy from one field(9) to another (10) and you'll see that several reg expressions are applied (tmp=~) to the data before it is copied over.
Code:
sub split_decode {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.

my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o; # Add a space if we have delimiter new line.
my (@array) = split (/\Q$db_delim\E/o, $input);
# start jury
$tmp = $array[9];
$tmp =~ s/ //g;
$tmp =~ s/\.//g;
$tmp =~ s/\*//g;
$tmp =~ s/<b>//g;
$tmp =~ s/<\/b>//g;
$tmp =~ s/º/ /g;
$tmp =~ s/&\s/&/g;
$tmp =~ s/'//g;
@array[10] = $tmp;
# end jury
for ($i = 0; $i <= $#array; $i++) {
$array[$i] =~ s/~~/$db_delim/og; # Retrieve Delimiter..
$array[$i] =~ s/``/\n/g; # Change '' back to newlines..
}
return @array;
}

------------------
JGU



[This message has been edited by jury (edited December 16, 1999).]
Quote Reply
Re: 'The %20 Situation' In reply to
Hello,

Firstly, thank you both for your replies. They were both helpful, but I had add some custom details.

First answer which was posted by Chris071371, made my fileds sepereted by + signs but letter by letter! Surely that did not solve the problem. (Though gave me an interesting idea about some other problem of mine Smile

Second one which was posted by jury was the closest match. But this one deleted the spaces between. (I wanted + or %20 for spaces) So I have chanced as below. I hope it can be helpful for others.

The code below inserts some code (it is %20 in this exampe) between words in your fields. This is necessarry for searches.

sub split_decode {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o; # Add a space if we have delimiter new line.
my (@array) = split (/\Q$db_delim\E/o, $input);
# start jury

$tmp = $array[26];
# next line defines the character but %20
# won't be visible on IE browsers, I don't
# know why... But when you click on it
# you'll see in adress bar. Huh !
# It searches for space and replaces with
# %20 which is the necessary character for
# defining a space at search. You may add
# + if you like but it makes a
# different search criteria.

$tmp =~ s/ /%20/g;

# This line is for your new formatted
# field number. (39 in here)

@array[39] = $tmp;

# I have disabled the following
# because they were not really necessary
# for me but can be useful to you.

# $tmp =~ s/\.//g; # delete dots
# $tmp =~ s/\*//g; # delete *
# $tmp =~ s/<b>//g; # delete bold
# $tmp =~ s/<\/b>//g; # delete bold
# $tmp =~ s/º/ /g; # delete º
# $tmp =~ s/&\s/&/g; # delete &
# $tmp =~ s/'//g; # delete '

# end jury
for ($i = 0; $i <= $#array; $i++) {
$array[$i] =~ s/~~/$db_delim/og; # Retrieve Delimiter..
$array[$i] =~ s/``/\n/g; # Change '' back to newlines..
}
return @array;
}



As mentioned above, this sub should bu inserted in db.cgi instead of the same named sub existing in db.cgi.

Also your field names for LINK fields should be different. My example changes 26 to 39.

Once more, thank you Chris, thank you Jury.

Long live Internet!


[This message has been edited by MserdarK (edited December 17, 1999).]