Gossamer Forum
Home : Products : Links 2.0 : Customization :

One way to have an add confirm:

Quote Reply
One way to have an add confirm:
Noticed a few people been wanting an add confirm mod which they've said is not avaiable. Here's a quick way to have a confirmation window appear before the link is added.

First go into add.html:

Replace:

<form action="<%db_cgi_url%>/add.cgi" method="POST">

With:

<form action="<%db_cgi_url%>/add.cgi" method="GET">
<input type = "hidden" name= "confirm" value = "yes">


Then open add.cgi and replace the whole of sub main with:


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

# We are processing the form.
if (keys %in != 0) {
my ($link, $link_output);
if (($ENV{'HTTP_REFERER'} =~ m,$build_root_url/(.+?)/?$,) and $in{'confirm'}) {
$link_output .= &site_html_link (%in) . "\n";

$link = $ENV{'QUERY_STRING'};
$link =~ s/&confirm=yes//;

print "Content-type: text/html\n\n";
print qq|
<html>
<head>
<title>Confirm details</title>
</head>
<body>
$link_output



Click <a href = "$db_cgi_url/add.cgi?$link">HERE</a>to confirm these details
</body>
</html>
|;
}
else{
&process_form;
}
}

# Otherwise we are displaying the form (in site_html.pl).
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 ();
}
}
}

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: One way to have an add confirm: In reply to
Yep...that's one way to do it...but there are other codes that are cleaner that do not include using a hidden field. Simple matter of using conditional statements, and adding a sub in the add.cgi script.

Regards,

Eliot Lee
Quote Reply
Re: One way to have an add confirm: In reply to
Yeah your right there's cleaner ways of doing it. I just figured I'd post a quick working solution as I don't have much free time to spend looking at these things at the moment.

To not need to add the hidden field, open add.cgi and instead replace the whole of sub main with (note you'll still need to use method ="GET" in add.cgi):

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

# We are processing the form.
if (keys %in != 0) {
my ($link, $link_output);
if ($in{'confirm'}) {
&process_form;
}

else{
if ($ENV{'HTTP_REFERER'} =~ m,$build_root_url/(.+?)/?$,){
$link_output .= &site_html_link (%in) . "\n";
$link = $ENV{'QUERY_STRING'};
print "Content-type: text/html\n\n";
print qq|
<html>
<head>
<title>Confirm details</title>
</head>
<body>
$link_output

Click <a href = "$db_cgi_url/add.cgi?confirm=yes&$link">HERE</a>to confirm these details
</body>
</html>
|;
}
else {
&site_html_add_form ();
}

}
}

# Otherwise we are displaying the form (in site_html.pl).
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 ();
}
}
}


Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: One way to have an add confirm: In reply to
Getting there...but could be cleaner and integrating it with the template system would be more user-friendly, than simply adding in extraneous HTML codes within the add.cgi script. But nice try...

Regards,

Eliot Lee
Quote Reply
Re: One way to have an add confirm: In reply to
Figured I could do with an add/modify site confirm option on a site I have in mind so I have done a little bit more work on it. I've tested it and it seems to work pretty well.

You don't need to alter add.html you only need to add a sub to site html templates.pl, alter add.cgi and create a confirmation template.

Add this sub to site html templates.pl:



sub site_html_confirm_add {
# --------------------------------------------------------
# This routine is used to display what a comment/review should look
# like.

&html_print_headers;

my $num = 0;
foreach $var (%in){
$num++;
}

$formvals .=qq|<form action= "add.cgi" method="POST">|;

for ($i = 0; $i < ($num/2); $i++) {
(($name, $value) = each %in);
$details .=qq|<b>$name:</b>$value
|;
$formvals .=qq|<input type="hidden" name="$name" value="$value">|;
}

$formvals .=qq|<input type="submit" name="add" value="Confirm Details"></form>|;

print &load_template ('add_confirm.html', {
details => $details,
formvals => $formvals,
%in,
%globals
});
}


Create a template called add_confirm.html containing the following tags:

<%details%>
<%formvals%>


In add.cgi replace:


# We are processing the form.
if (keys %in != 0) {
&process_form;
}


with:

# We are processing the form.
if (keys %in != 0) {
$in{'add'}? &process_form : &site_html_confirm_add;
}



Could also easliy alter the confirm add sub so that the details are printed in a table... Can also easily be altered to work for modifying a site




Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: One way to have an add confirm: In reply to
Hello,

I'm sorry, but I can't get either of these methods to work?
Am I doing something wrong???? I don't use templates...
When the form is submitted it always displays my output page saying it was succesful, any ideas?

Thanks,
Brett

Quote Reply
Re: One way to have an add confirm: In reply to
Have you remembered to make the alterations in add.cgi?

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: One way to have an add confirm:BUT with mods?? In reply to
Hi Glennu,
First - Thanks for what you do here!
Now
I had the add confirm set up as you say here. But it slowed spammers down, but did not stop them. So I went to your site here: http://cgi-resource.co.uk/pages/links2mods.shtml
and installed your EASY mod called: STOP REPEAT SUBMITION -
I tested it all and it works great, however, before I did this, I did not realize that my add confirm would be given up when I replaced the - sub main - area of the file.

Do you have or can you create a method, mod that allows for both, -
Or first the add confirm, on the first submition if the person has not been there in a while, then also checks the ip addy and does not allow a submition soon after the first.

This would be great !!

Also, can you tell me how I can change the allowed time, as to when another post may be submitted??

Thanks Tammy

Quote Reply
Re: One way to have an add confirm:BUT with mods?? In reply to
I did put together an add confirm mod that also generated a password key that the user had to enter before they could add their site.

Once I've finished exams I'll dig it up and post it.


Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml