Gossamer Forum
Home : Products : Links 2.0 : Customization :

Checkbox in add.cgi

Quote Reply
Checkbox in add.cgi
I just need a checkbox in add.cgi so users can give an agreement to the "terms of use"
I found a javascript whick enables the add-button until zu check the checkbox
BUT
I dont know how to integrate the script in the the links 2.0 form in add.cgi, so that the add.cgi button is enabled until you check the checkbox?

Here is the javascript
Code:

<SCRIPT language=JavaScript>
<!--
function checkCheckBox(f){
if (f.agree.checked == false )
{
alert('Bitte klicken Sie die Checckbox an, um fortzufahren.');
return false;
}else
return true;
}
//-->
</SCRIPT>
<form action="" method="GET" onsubmit="return checkCheckBox(this)">
<b>Durch Abschicken des Formulars erkläre ich, die AGBs gelesen und akzeptiert zu haben.</b><br>
AGBs gelesen und akzeptiert: <input type="checkbox" value="0" name="agree">
<input type="submit" value="weiter">
</form>



And here is my add.cgi form
Code:

<p class="dateinormal"><font size="2"><b>&nbsp;</b></font>
<form action="<%db_cgi_url%>/eintrag.cgi" method="POST">
<div align="center">
<center>
<table border ="0" cellspacing="1" cellpadding="3">
<tr>
<td valign="top" nowrap><b><font size="2">Titel:</font></b></td>
<td valign="top">
<input name="Titel" size="40">
</td>
</tr>

<tr>
<td valign="top" nowrap></td>
<td valign="top">
<input type=hidden name="URL" size="30">
</td>
</tr>

<tr>
<td valign="top" nowrap><b><font size="2">Kategorie:</font></b></td>
<td valign="top"><font size="2">
<%Kategorie%>
</font></td>
</tr>
<tr>
<td valign="top" nowrap><b><font size="2">Beschreibung:</font></b></td>
<td valign="top">
<textarea wrap="virtual" name="Beschreibung" value="" rows="5" cols="35"></textarea>
</td>
</tr>
<tr>
<td valign="top" nowrap><b><font size="2">Name:</font></b></td>
<td valign="top">
<input name="Name" size="30">
</td>
</tr>
<tr>
<td valign="top" nowrap><b><font size="2"> Email:</font></b></td>
<td valign="top">
<input name="Email" size="30">
</td>
</tr>
<tr>
<td></td>
<td>
<input type="SUBMIT" value="Daten eintragen" name="SUBMIT" class=button>&nbsp;&nbsp;
</center>
<pre class="zitat">Bitte nur einmal klicken !!!</pre>
</td>
</tr>
</table>
</div>
</form>


Can anyone help me?
Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Checkbox in add.cgi In reply to
I found a solution!
Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Checkbox in add.cgi In reply to
What is your solution?

Links will create checkbox fields, and you could add a simple 'if' statement to add.cgi to verify that the box is checked, eliminating the need for javascript.

1. Tag in form:

Code:
<%Agree%>


Will creat this HTML:

Code:
<input type="checkbox" name="Agree" value="Yes" />




2. Code in links.def

Code:
Agree => [18, 'alpha', 10, 10, 0, 'No', 'No|Yes'],
--

$db_agree = 18;

--

# Checkbox fields; when checked, 'Yes' will be selected and db will show 'Yes', otherwise 'No' is selected and the field will be empty.
%db_checkbox_fields = (
Agree => 'Yes'

);




3. Code in site_html_templates.pl:

Code:
Agree => &build_checkbox_field ('Agree',Yes),



4. Code in add.cgi:

Code:

# We are processing the form.
if (keys %in != 0) {
($in{'Agree'} = 'Yes') ? &process_form : &site_html_add_failure("You did not agree to the terms.") and return;
}


Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Mar 5, 2006, 1:57 PM
Quote Reply
Re: [PerlFlunkie] Checkbox in add.cgi In reply to
Just remembered that the above code is based on a field in the database (which would need to be added to links.db), and which you don't need just for what you want. So, skip steps 1-3, do step 4, and use this in your form:

Code:
<input type="checkbox" name="Agree" value="Yes" />


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Checkbox in add.cgi In reply to
Hi Leonard,
my solution is "just another site" before add.html ;-)
So I prefer your way, it's more elegant.

The way without the db-changes is good for me.
But I have problems with the changes?

After the changes in add.cgi and add.html, there is a checkbox, but it does'nt matter if the checkbox is enabled or disabled. Even when the checkbox is not clicked, there is an entry in the database after the click on the add-button.

Here are my code changes in add.html
Code:


<form action="<%db_cgi_url%>/eintrag.cgi" method="POST">
<div align="center">
<center>
<table border ="0" cellspacing="1" cellpadding="3">
<tr>
<td valign="top" nowrap><b><font size="2">Titel:</font></b></td>
<td valign="top">
<input name="Titel" size="30">
</td>
</tr>

</center>
<tr>
<td valign="top"><b><font size="2">URL:</font></b></td>
<center>
<td><input name="URL" size="30" value="http://"></td>
</tr>

<tr>
<td valign="top" nowrap><b><font size="2">Kategorie:</font></b></td>
<td valign="top"><font size="2">
<%Kategorie%>
</font></td>
</tr>
<tr>
<td valign="top" nowrap><b><font size="2">Beschreibung:</font></b></td>
<td valign="top">
<textarea wrap="virtual" name="Beschreibung" value="" rows="5" cols="35"></textarea>
</td>
</tr>
<tr>
<td valign="top" nowrap><b><font size="2">Name:</font></b></td>
<td valign="top">
<input name="Name" size="30">
</td>
</tr>
<tr>
<td valign="top" nowrap><b><font size="2"> Email:</font></b></td>
<td valign="top">
<input name="Email" size="30">
<p>&nbsp;</p>
</td>
</tr>
<tr>
<td valign="top" nowrap><b><font size="2">Bestätigung:</font></b></td>
<td valign="top">
<input type="checkbox" name="Agree" value="Yes" />Ich
garantiere, dass dass ich der/die AutorIn der
Materialien bin. Ich habe das Recht, die Materialien
zu veröffentlichen und verletze damit keine
Urheberrechte. Zudem erlaube ich allen Benutzern von
www.gpaed.de, meine Materialien für andere Schüler
zu verändern und im Unterricht einzusetzen.
<p>&nbsp;
</td>
</tr>
<tr>
<td></td>
<td>
<input type="SUBMIT" value="Daten eintragen" name="SUBMIT" class=button>&nbsp;&nbsp;
</center>
<pre class="zitat">Bitte nur einmal klicken !!!</pre>
</td>
</tr>
</table>
</div>
</form>


and here are my changes in add.cgi
Code:


sub main {
# --------------------------------------------------------
local (%in) = &parse_form;

# We are processing the form.
if (keys %in != 0) {
($in{'Agree'} = 'Yes') ? &process_form : &site_html_add_failure("Klicken Sie das Kästchen zur Bestätigung.") and return;
}

else {
if ($db_single_category) {
my %is_valid = map { $_ => 1 } &category_list;
$ENV{'HTTP_REFERER'} =~ s,/[^/]+\.[^/]+$,,;
$ENV{'HTTP_REFERER'} =~ m,$build_root_url/(.+?)/?$,;
$is_valid{$1} ? &site_html_add_form ($1) : &site_html_add_form ();
}
else {
&site_html_add_form ();
}
}
}



But I'm not sure if I found the right place for the code in add.cgi?

Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Checkbox in add.cgi In reply to
Yes, you put the code in the right place. Try this:

old
($in{'Agree'} = 'Yes')

new
($in{'Agree'} eq 'Yes')


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Checkbox in add.cgi In reply to
Hi Leonard,
now it works perfect. I like your solution!
Thank you again and again... Smile
Matthias

Matthias
gpaed.de