Gossamer Forum
Home : Products : Links 2.0 : Customization :

How to remove ~~ in links.db with checkbox

(Page 1 of 2)
> >
Quote Reply
How to remove ~~ in links.db with checkbox
Hi all,
I searched throug all possible threads about removing ~~ in my new added field in links.db.
The problem is that i want to use checkbox for multiplay selecting language for resourse. (Russian, Deutsch, English).
I use modification for language resourses (image-flag), posted in:
http://www.gossamer-threads.com/...=&vc=1#Post48583. But nothing works for me. I am getting no language flags.
My quastion is how to get russian|deutsch|english| insted of russian~~deutsch~~english in links.db?

Or may be there is another solution for choosing languge for resource using multiplay checkbox selection?
Thanks in advance for your help,

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
For checkboxes, you have to create three different fields....English, Deutsch, Russian in the _def section, then use the following codes in the db_radio_fields hash:

Code:

English => 'English',
Deutsch => 'Deutsch',
Russian => 'Russian'


I would recommend doing the following:

1) Add the following sub in your site_html_templates.pl file:

Code:

sub build_fancy_mult_field {
# --------------------------------------------------------#
# Multiple Select Field for Languages

$size = "5";
my $field = $_[0];
my $compare = $_[1];
my %selector = (
'Language' => [
['---','Choose as many that apply:'],
['eng','English'],
['de','Deutsch'],
['ru','Russian'],
],
);
$output = qq|<SELECT NAME="$field" MULTIPLE SIZE="$size">\n|;
$i = 0;
while ( $selector{$field}[$i][0] ) {
$compare =~/$selector{$field}[$i][0]/ ?
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]" SELECTED>$selector{$field}[$i][1]\n|) :
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]">$selector{$field}[$i][1]\n|);
++$i;
}
if ($i) {
$output .= "</SELECT>";
}
else {
$output = "Incorrect field definition";
}
return $output;
}


2) Then add the following codes in your sub site_html_add_form, sub site_html_add_failure, sub site_html_modify_form, and sub site_html_modify_failure routines in the site_html_templates.pl file:

Code:

my $language = &build_clean($language);
$language = &build_fancy_mult_field ("Language", $in{'Language'});


Then define the following tag IN THESE SUBS:

Code:

language => $language


3) Then in your add.html, add_error.html, modify.html, and modify_error.html files, add the following codes:

Code:

Choose Language: <%language%>


NOTE: You will notice that I use abbreviations for the languages...change the abbreviations to the full language if you want.

BTW: You will still get the same result in the links.db file:

Code:

English~~Deutsch~~Russian


The ~~ stands for separating multiple values for the same field in the database file.

Get it?

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Hi Eliot and thanks once again for your will and time to help "dummies".
I am using not radio fields, but checkbox, and want multiplay selection wthin checkbox.

Ok. I will try your suggestion for checkbox.

Thanks

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Can't be done.

Use one of the suggestions I gave you.

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Thanks Elilot,

I will try your code in radio_field .

One more question. I have put in my links.def the code, where i wanted to use language choose mod with checkbox:
#Adding checkboxes field <INPUT TYPE="CHECKBOX">.
_checkbox_fields = ( "my choice here");

No chance to do this with multiplay selection?

Ankom

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
You can try:

Code:

Language => 'Deutsch,English,Russian'


BTW: You are still going to get the same result:

Code:

value1~~value2~~value3


Do you even understand what the ~~ codes do???? I tried explaining it in laymen terms above! Tongue

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Yes, I got this. I will try both of your suggested variants.

Thanks for your time.

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
You're welcome.

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Hi there.
If you want to be able to use multiple languages, put something like this in your add- and modify pages and anywhere else needed:

Code:
<tr>
<td valign="top" align="left"><input type="checkbox" name="Sprache" value="D"><img src="path/to/picture.gif"> -
<input type="checkbox" name="Sprache" value="S"><img src="path/to/picture.gif"> -
<input type="checkbox" name="Sprache" value="A"><img src="path/to/picture.gif"> -
<input type="checkbox" name="Sprache" value="N"><img src="path/to/picture.gif"> -
<input type="checkbox" name="Sprache" value="E"><img src="path/to/picture.gif"></td>
</tr>
Each value of above checkboxes represents the abriviation for one language. Do not use the same letter for
2 languages then. Actually one may use sub build_checkbox_field for the stuff above, but I found that out only after inserting my codes, so I never changed it.

To keep the links.db small and clean put the following code in search.cgi
Code:
# Die Delimeter in $in{'Sprache'} mssen herausgefilter werden... DC
if ($in{'Sprache'}) {
@sprache = split /\~\~/,$in{'Sprache'};
$in{'Sprache'} = join ("",@sprache);
}
right after those codes:

Code:
# Check the referer.
if (@db_referers and $ENV{'HTTP_REFERER'}) {
$found = 0;
foreach (@db_referers) {
$ENV{'HTTP_REFERER'} =~ /$_/i and $found++ and last;
}
if (!$found) {
&site_html_add_failure ("Auto submission is not allowed in this directory. Please visit the site to add your entry.");
return;
}
}
In your links.def add another field called "Sprache" (or "language", but then also change the name field of the checkboxes and anywhere else you find "SPrache"...).
This new field in links.def might look like this:
Sprache => [17, 'alpha', 5, 3, 0, 'D', 'D|S|A|E|N'],

Don't forget to delete the comma if it's your last field in the list. Also change the 17 to the running field number that fits your links.def. The D|S|A|E|N represents all letters allowed for the field. Change it to fir your requirements.
A little bit below you may also want to add under # Field Number of some important fields. something like $db_Sprache = 17; for future use...

In your existing links.db don't forget to put another delimiter to whereever the place of the new field will be...

I'm using non-templates, so I'll just put the coding for this here:
In site_html.pl put the follwowing code at the place wherever you want to show up the flags:

Code:
# Show_Language MOD. Denis Campbell 2000 -------------
if ($rec{'Sprache'}) { $output .= qq~<small class="date">~;}
if($rec{'Sprache'} =~ /D/i) # If entry includes "D" ...
{ $output .= qq~<img src="path/to/picture.gif"> \n~; } # ...show German flag
if($rec{'Sprache'} =~ /S/i) # Or if entry includes "S" ...
{ $output .= qq~<img src="path/to/picture.gif"> \n~; } # ...show Switzerland flag
if($rec{'Sprache'} =~ /A/i) # ...and so on ...
{ $output .= qq~<img src="path/to/picture.gif"> \n~; }
if($rec{'Sprache'} =~ /N/i)
{ $output .= qq~<img src="path/to/picture.gif"> \n~; }
if($rec{'Sprache'} =~ /E/i)
{ $output .= qq~<img src="path/to/picture.gif"> \n~; }
if ($rec{'Sprache'}) { $output .= qq~</small>~; }
# End Show_Language MOD ----------------------------------
ok, that should be it. Hope I didn't miss something important cause I put this in my LINKS long time ago. You can leave me message here if something's not running, for me it is 100%.
Just in short how it works: The new field in the database contains one letter for each possible language. Using a regular expression you can find out which flags you will want to show for each link.

If you want to, see it here: http://www.bikerlinks.de . Behind "Seite eintragen" you'll find the add-page. You can even play around a little by pressing the add button once to see how it works (not all combination of flags are allowed), because there's an add-confirm page after that. But pls. do me a real favour and don't bomb me with test-adds, thanks!

Ah, this filter for the combinations is not in above coding. It's just another reg. expr. saying if it's this language this other one is not allowed, so put that letter out again.

Denis

PS: hope there's noone else who did this mod before, actually I never found something and since I do not seem to be the only one I posted my codes here...


Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Denis,

Hello...and again you need to translate the codes for TEMPLATE users! You are one of the few users who use the site_html.pl file.

So, added instructions for template users would be nice! (I know how to do it...I am asking for the benefit of other novice users).

Goodbye!

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Hi Eliot,

I took a glance at the template-files, but since I never used them I was'nt able to figure out the way they work at the moment. Unfortunately I will not find the time to take a closer look, so if you don't mind I'd be very thankful if maybe you could in short add the steps that template-users have to follow.

Or maybe anyone else? Thank you in advance in the name of all template-users...

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Actually, the only codes you need to change are the following:

Code:

# Show_Language MOD. Denis Campbell 2000 -------------
if ($rec{'Sprache'}) { $output .= qq~<small class="date">~;}
if($rec{'Sprache'} =~ /D/i) # If entry includes "D" ...
{ $output .= qq~<img src="path/to/picture.gif"> \n~; } # ...show German flag
if($rec{'Sprache'} =~ /S/i) # Or if entry includes "S" ...
{ $output .= qq~<img src="path/to/picture.gif"> \n~; } # ...show Switzerland flag
if($rec{'Sprache'} =~ /A/i) # ...and so on ...
{ $output .= qq~<img src="path/to/picture.gif"> \n~; }
if($rec{'Sprache'} =~ /N/i) { $output .= qq~<img src="path/to/picture.gif"> \n~; }
if($rec{'Sprache'} =~ /E/i) { $output .= qq~<img src="path/to/picture.gif"> \n~; }
if ($rec{'Sprache'}) { $output .= qq~</small>~; }
# End Show_Language MOD ----------------------------------


You need to change the above codes to the following:

Code:

# Show_Language MOD. Denis Campbell 2000 -------------
if ($rec{'Sprache'}) {
$langimg = qq|<small class="date">|;
}
if ($rec{'Sprache'} =~ /D/i) {
$langimg = qq|<img src="path/to/picture.gif">|;
}
if ($rec{'Sprache'} =~ /S/i) {
$langimg = qq|<img src="path/to/picture.gif">|;
}
if ($rec{'Sprache'} =~ /A/i) {
$langimg = qq|<img src="path/to/picture.gif">|;
}
if ($rec{'Sprache'} =~ /N/i) {
$langimg = qq|<img src="path/to/picture.gif">|;
}
if ($rec{'Sprache'} =~ /E/i) {
$langimg = qq|<img src="path/to/picture.gif">|;
}
if ($rec{'Sprache'}) {
$langimg = qq|</small>|;
}
# End Show_Language MOD ----------------------------------


Put these codes in the sub site_html_link routine AFTER the following codes:

Code:

my (%rec) = @_;


Then define the langimg tag as follows:

Code:

langimg => $langimg


if this is NOT the last tag defined in the load_template hash, then add a comma AFTER $langimg.

Then in your link.html file, add the following tag:

Code:

<%langimg%>


Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Hi Eliot and Denis,

I tried your Code, what you submitted above and it works.
But it is for Select field.

May be it would be better if I post my Code here. (

And I am trying to use language selector with checkboxes. The code
(taken from http://www.gossamer-threads.com/perl/forum/showthreaded.pl?Cat=&Board=L2Cust&Number=48583&page=&view=&sb=&vc=1)
in links.def

# Definition of your database file.
_def = (

ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes'],
Password => [14, 'alpha', 10, 10, 1, '', ''],
Key => [15, 'alpha', 40, 150, 1, '', ''],
isBest => [16, 'alpha', 0, 5, 0, 'No', ''],
Language => [17, 'alpha', 0, 60, 1, '','russian|deutsch|english']
);

Still in links.def
#Adding checkboxes field <INPUT TYPE="CHECKBOX">.
_checkbox_fields = (
Language => 'russian,deutsch,english'
);

in site_html_templates.pl

$russian = qq|<img src="../../images/russian.gif" alt="Russian">|;
$deutsch = qq|<img src="../../images/deutsch.gif" alt="Deutsch">|;
$english = qq|<img src="../../images/english.gif" alt="English">|;
$russian_deutsch = qq|<img src="../../images/russian_deutsch.gif" alt="Russian, Deutsch">|;
$russian_english = qq|<img src="../../images/russian_english.gif" alt="Russian, English">|;
$russian_deutsch_english = qq|<img src="../../images/russian_deutsch_english.gif" alt="Russian, Deutsch, English">|;

And then

%globals = (
date => &get_date,
time => &get_time,
db_cgi_url => $db_cgi_url,
build_root_url => $build_root_url,
site_title => $build_site_title,
css => $build_css_url,
russian => $russian,
deutsch => $deutsch,
english => $english,
russian_deutsch => $russian_deutsch,
russian_english => $russian_english,
russian_deutsch_english => $russian_deutsch_english,
deutsch_english => $deutsch_english,
banner => ''
);

And then

sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;



if ($rec{'Type1'} eq "russian") {
$type1img = $russian;
}
elsif ($rec{'Type1'} eq "deutsch") {
$type1img = $deutsch;
}
elsif ($rec{'Type1'} eq "english") {
$type1img = $english;
}
elsif ($rec{'Type1'} eq "russian|deutsch") {
$type1img = $russian_deutsch;
}
elsif ($rec{'Type1'} eq "russian|english") {
$type1img = $russian_english;
}
elsif ($rec{'Type1'} eq "russian|deutsch|english") {
$type1img = $russian_deutsch_english;
}
elsif ($rec{'Type1'} eq "deutsch|english") {
$type1img = $deutsch_english;
}
else {
$type1img .= $type1img .= qq| No image |;
}
And then

return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
type1img => $type1img,
%rec,
%globals
});
}

And in sub site_html_add_form
#----------------------------------- Add new checkbox field for Language------------------
my $language = shift;
$language ?
($language = qq~$language <input type=hidden name="Language" value="$language">~) :
($language = &build_checkbox_field ("Language", "$in{'Language'}"));
#----------------------------------- End of adding checkboxes for Language-----------------
print &load_template ('add.html', {
Category => $category,
Language => $language,
%globals
});
}

In add.html i use
<td><font face="Verdana" size="-1">
<input type="checkbox" name="Language" value="russian">
<img src="../../images/russian.gif"> -
<input type="checkbox" name="Language" value="deutsch">
<img src="../../images/deutsch.gif"> -
<input type="checkbox" name="Language" value="english">
<img src="../../images/english.gif">
</font></td></tr>

And in add.cgi I use Code submited by Denis:

if ($in{'Language'}) {
@language = split /\~\~/,$in{'Language'};
$in{'Language'} = join ("",@language);
}

And then in link.html trying to use <%type1img%>

My problem (how i think) is what i cannot extract from field "language" in links.db russian|deutsch or other possible language combination, inputed in add.html.

Can anybody help me to solve this problem for Template?

Sorry for the long Post. I don't know if it's allowd in this forum.

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Sure you can!!!

You need to change the following codes:

Code:

if ($rec{'Type1'} eq "russian") {
$type1img = $russian;
}
elsif ($rec{'Type1'} eq "deutsch") {
$type1img = $deutsch;
}
elsif ($rec{'Type1'} eq "english") {
$type1img = $english;
}
elsif ($rec{'Type1'} eq "russian|deutsch") {
$type1img = $russian_deutsch;
}
elsif ($rec{'Type1'} eq "russian|english") {
$type1img = $russian_english;
}
elsif ($rec{'Type1'} eq "russian|deutsch|english") {
$type1img = $russian_deutsch_english;
}
elsif ($rec{'Type1'} eq "deutsch|english") {
$type1img = $deutsch_english;
}
else {
$type1img .= $type1img .= qq| No image |;
}


to the following:

Code:

if ($rec{'Type1'} eq "russian") {
$type1img = $russian;
}
elsif ($rec{'Type1'} eq "deutsch") {
$type1img = $deutsch;
}
elsif ($rec{'Type1'} eq "english") {
$type1img = $english;
}
elsif (($rec{'Type1'} eq "russian") and ($rec{'Type1'} eq "deutsch")) {
$type1img = $russian_deutsch;
}
elsif (($rec{'Type1'} eq "russian") and ($rec{'Type1'} eq "english")) {
$type1img = $russian_english;
}
elsif ((($rec{'Type1'} eq "russian") and ($rec{'Type1'} eq "deutsch") and ($rec{'Type1'} eq "english"))) {
$type1img = $russian_deutsch_english;
}
elsif (($rec{'Type1'} eq "deutsch") and ($rec{'Type1'} eq "english")) {
$type1img = $deutsch_english;
}
else {
$type1img .= $type1img .= qq| No image |;
}


Notice the bolded red codes.

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Thousand thanks Eliot.

I will try this now

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
You're welcome.

WinkSmile

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
God bless you Eliot and Denis.
It starts to work. But I still have one small problem with showing up differnet image-flag in links.html in case of multiplay selection.

I have (in following oder) russian, german, english to select.

When user selects only one of the language - everything is fine.
When user selects russian and german - only german image-flag is showing up
When user selects russian and english - everything is fine
When user selects russian,german and english - only german and english image flag
When user selects english and german - everything is fine

That is what I have in my links.def
.............
Language => [17, 'alpha', 3, 60, 1, '',''] (my last field)
......................
#Adding checkboxes field <INPUT TYPE="CHECKBOX">.
_checkbox_fields = (
Language => 'russian,german,english'
);

And this in my site_html_template.pl:

# Show_Language MOD. Denis Campbell 2000 -------------
if ($rec{'Language'} =~/russian/i) {
$langimg = qq|<img src="../images/russian.gif">|;
}
if ($rec{'Language'} =~/german/i) {
$langimg = qq|<img src="../images/german.gif">|;
}
if ($rec{'Language'} =~ /english/i) {
$langimg .= qq|<img src="../images/english.gif">|;
}

# End Show_Language MOD ----------------------------------

What is the problem? I tryed to experiment with the ~/german/i, but the same results.

Can you give me some hits?

Thanks for assistence


Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
USE THE CODES I PROVIDED! IT WILL WORK!

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Hi Eliot,
thanks again and again,

I use exact Code you provided in this thread.
http://gossamer-threads.com/...= collapsed&sb=5
In Reply To:
Actually, the only codes you need to change are the following:

# Show_Language MOD. Denis Campbell 2000 -------------
if ($rec{'Sprache'}) { $output .= qq~<small class="date">~;}
................and so on
You need to change the above codes to the following:

# Show_Language MOD. Denis Campbell 2000 -------------
if ($rec{'Sprache'}) {
$langimg = qq|<small class="date">|;
..................and so on


All others are either with Select fields or didn't work for me.

Thanks once again for your time and support.

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Uh...USE THE CODES IN THIS THREAD!

Tongue

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Sorry Eliot for a stupied question,
What Code do you mean? All Codes, besides Denis's didn't work for me.

Never mind. I really don't want to waste your time. I will ask Denis tomorrow.

Thanks for your assistance

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
THESE CODES:

Code:

if ($rec{'Type1'} eq "russian") {
$type1img = $russian;
}
elsif ($rec{'Type1'} eq "deutsch") {
$type1img = $deutsch;
}
elsif ($rec{'Type1'} eq "english") {
$type1img = $english;
}
elsif (($rec{'Type1'} eq "russian") and ($rec{'Type1'} eq "deutsch")) {
$type1img = $russian_deutsch;
}
elsif (($rec{'Type1'} eq "russian") and ($rec{'Type1'} eq "english")) {
$type1img = $russian_english;
}
elsif ((($rec{'Type1'} eq "russian") and ($rec{'Type1'} eq "deutsch") and ($rec{'Type1'} eq "english"))) {
$type1img = $russian_deutsch_english;
}
elsif (($rec{'Type1'} eq "deutsch") and ($rec{'Type1'} eq "english")) {
$type1img = $deutsch_english;}

else {
$type1img .= $type1img .= qq| No image |;
}


HOWEVER, after looking at the codes...there are some errors, which
I did not clean up for you...

USE the following codes:

Code:

if ($rec{'Type1'} eq "russian") {
$type1img = qq|$russian|;
}
if ($rec{'Type1'} eq "deutsch") {
$type1img = qq|$deutsch|;
}
if ($rec{'Type1'} eq "english") {
$type1img = qq|$english|;
}
elsif (($rec{'Type1'} eq "russian") and ($rec{'Type1'} eq "deutsch")) {
$type1img = qq|$russian_deutsch|;
}
elsif (($rec{'Type1'} eq "russian") and ($rec{'Type1'} eq "english")) {
$type1img = qq|$russian_english|;
}
elsif ((($rec{'Type1'} eq "russian") and ($rec{'Type1'} eq "deutsch") and ($rec{'Type1'} eq "english"))) {
$type1img = qq|$russian_deutsch_english|;
}
elsif (($rec{'Type1'} eq "deutsch") and ($rec{'Type1'} eq "english")) {
$type1img = qq|$deutsch_english|;
}

else {
$type1img .= qq| No image |;
}


By removing the operators qq| and |;, the codes will not work.

Regards,

Regards,

Eliot Lee
Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Thanks Eliot,

I will try this.

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Eliot, no more English words to express how greatfull to you i am

And the most last question to you.
Is there any possibility to use Code, which Denis submited in this thread above, but only with Templates mod and corrected by you?

Greatfully yours

Quote Reply
Re: How to remove ~~ in links.db with checkbox In reply to
Uh...I don't understand your question...I HAVE already edited the codes you need to use for Templates!!!!

READ my POSTS AGAIN CAREFULLY!

*sigh*

Regards,

Eliot Lee
> >