Gossamer Forum
Home : Products : Links 2.0 : Discussions :

adding an entry/add.cgi

Quote Reply
adding an entry/add.cgi
When I submit the add form that posts to add.cgi it just refreshes the page and loads the blank form again. I know the issue is with the following code since if I change if (keys %in != 0) { to if (keys %in == 0) { it attempts to process the form when I load it. So for some reason keys %in is always == 0, no matter what fields I have filled in on my form.

# We are processing the form.
if (keys %in != 0) {
&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 ()
}
}

Any suggestions/help would be appreciated, let me know if you need more info. Thanks in advance
Quote Reply
Re: [Johnny23] adding an entry/add.cgi In reply to
Wrong forum Wink (I've moved it for you)

It could be a couple of things:

1) Your form in the HTML is corrupt, and thus its not sending any useful values
2) There is another hack you've done thats stopped it working - when did it stop working, and what were your last "tweaks"?

You could try adding:

Code:
use Data::Dumper;
print "Content-Type: text/html \n\n";
print "<pre>" . Dumper(%in) . "</pre>";

if (keys %in != 0) {
&process_form;
}

..and then see what gets printed out (i.e if any values are actually sent). I'm afraid I'm a bit rusty with Links2, as I tend to work only with the SQL products.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] adding an entry/add.cgi In reply to
I added

use Data::Dumper;
print "Content-Type: text/html \n\n";
print "<pre>" . Dumper(%in) . "</pre>";

above

if (keys %in != 0) {
&process_form;
}

seems like there aren't any values actually being sent when using the following form

<FORM ACTION="$build_add_url" METHOD="POST" >
Complete the form below to add your listing. Please allow 48 hours for your listing to be indexed.<br><br>
<u><strong>Contact information:</strong></u><blockquote>
<table border = 0 bgcolor="#FFFFDF">
<tr><td valign=top><$font>Company/Organization:</font></td>
<td><INPUT NAME="Title" VALUE="$in{'Title'}" SIZE=25></td></tr>
<tr><td valign=top><$font>Contact Name:</font></td>
<td><INPUT NAME="Contact Name" VALUE="$in{'Contact Name'}" SIZE=25></td></tr>
<tr><td valign=top><$font>Website URL:</font><br><font size=2>(include the http://)</font></td>
<td><INPUT NAME="URL" VALUE="$in{'URL'}" SIZE=40></td></tr>
<tr><td colspan=2>Please suggest a <u><strong>directory category</strong></u>
that best describes your business or activity ( i.e. campground or adventure ).</td></tr>
<tr><td valign=top><$font>Category:</font></td>
<td><font size=2>~; $db_select_fields{'Category'} = join (",", &category_list); print &build_select_field ("Category", "$in{'Category'}"); print qq~</font></td></tr>
<tr><td valign=top><$font>Street or P.O. Box #:<font></td>
<td><INPUT NAME="Address" VALUE="$in{'Address'}" SIZE=25></td></tr>
<tr><td valign=top><$font>City, Prov/State:</font></td>
<td><INPUT NAME="CityProv" VALUE="$in{'CityProv'}" SIZE=25></td></tr>
<tr><td valign=top><$font>Zip or Postal Code:</font></td>
<td><INPUT NAME="PostalCode" VALUE="$in{'PostalCode'}" SIZE=25></td></tr>
<tr><td valign=top><$font>Phone:</font></td>
<td><INPUT NAME="Phone" VALUE="$in{'Phone'}" SIZE=25></td></tr>
<tr><td valign=top><$font>Fax:</font></td>
<td><INPUT NAME="Fax" VALUE="$in{'Fax'}" SIZE=25></td></tr>
<tr><td valign=top><$font>Email:</font></td>
<td><INPUT NAME="Contact Email" VALUE="$in{'Contact Email'}" SIZE=40></td></tr>
</table></center>
</blockquote>
<p>Please enter a <u><strong>brief description</strong></u> of the service, program or
product offered in the space below, and include a <strong><u>short description</u></strong> of how we might find you in relation to the major highway systems in the province ( i.e. Route 2, off Highway #104, at
exit 18 ):<br>

<TEXTAREA NAME="Description" VALUE="$in{'Description'}" ROWS=8 COLS=60>$in{'Description'}</TEXTAREA></p>

<hr size=1 width=500 align=left>
<INPUT TYPE="SUBMIT" VALUE="Add Listing">
</form>

when I change
<FORM ACTION="$build_add_url" METHOD="POST" > to <FORM ACTION="$build_add_url" METHOD="GET" > I get the following output

$VAR1 = 'URL';
$VAR2 = 'http%3A%2F%2Fwww.test.com';
$VAR3 = 'Contact Email';
$VAR4 = 'test%40test.com';
$VAR5 = 'PostalCode';
$VAR6 = 'Test';
$VAR7 = 'Address';
$VAR8 = 'Test';
$VAR9 = 'Title';
$VAR10 = 'Test';
$VAR11 = 'CityProv';
$VAR12 = 'Test';
$VAR13 = 'Phone';
$VAR14 = 'Test';
$VAR15 = 'Contact Name';
$VAR16 = 'Test';
$VAR17 = 'Description';
$VAR18 = 'Test';
$VAR19 = 'Category';
$VAR20 = 'Accommodation';
$VAR21 = 'Fax';
$VAR22 = 'Test';

and it gives the following error

There were the following errors trying to add your resource:

  • Contact Email (Invalid format)

Please fill out any missing fields and try again!

any other sugestions/help would be appreciated, let me know if you need more info. Thanks in advance
Quote Reply
Re: [Johnny23] adding an entry/add.cgi In reply to
Mmm, I'm not too sure to be honest - I guess one way would be to build up %in using CGI.pm:

Code:
my $q = CGI->new();

my %in;
for my $key ( $q->param() ) {
$in{$_} = $q->param($_);
}

The old code for getting %in is a bit outdated (as CGI.pm handles it much more elegantly, or GT::CGI in LinksSQL and their other newer scripts)

Hope that helps.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] adding an entry/add.cgi In reply to
sorry for the stupid question but where would I put that code? I don't have much experience with this.
Quote Reply
Re: [Johnny23] adding an entry/add.cgi In reply to
I'm afraid I don't have a copy of Links2 to hand (as I said, its been a while since I've used it =))

I guess look in the code to see where %in is created. Maybe do a search for:

Code:
%in =

That will hopefully put you on the right tracks Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Johnny23] adding an entry/add.cgi In reply to
Did you get the form working?


Leonard
aka PerlFlunkie