This has been a real challenge!
Getting Links to remember everything during the Add Confirm process requires a bit of changing in add.cgi. This may not be the best way to do it, but it seems to work, even the error pages!
In
add.cgi:
sub main {
# --------------------------------------------------------
local (%in) = &parse_form;
# We are processing the form.
if ((keys %in != 0) && ($in{'do'} eq 'confirm')) {
&process_form;
}
elsif ((keys %in != 0) && ($in{'do'} eq 'add')) {
&process_form_2;
} # 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 ();
}
}
}
sub process_form {
# --------------------------------------------------------
my ($key, $status, $line, $output);
# 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;
}
}
# This will set system fields like Validated to their proper values.
foreach $key (keys %add_system_fields) {
$in{$key} = $add_system_fields{$key};
}
# Set date variable to today's date.
$in{$db_cols[$db_modified]} = &get_date;
open (ID, "<$db_links_id_file_name") or &cgierr("error in process_form. unable to open id file: $db_links_id_file_name. Reason: $!");
$in{$db_key} = <ID> + 1; # Get next ID number
close ID;
# Validate the form input..
$status = &validate_record(%in);
if ($status eq "ok") {
# Update the counter.
open (ID, ">$db_links_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_links_id_file_name. Reason: $!");
flock(ID, 2) unless (!$db_use_flock);
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
# Send the visitor to the add confirm page.
&site_html_confirm_add;
}
else {
&site_html_add_failure($status);
}
} sub process_form_2 {
# --------------------------------------------------------
my ($key, $status, $line, $output); # This will set system fields like Validated to their proper values.
foreach $key (keys %add_system_fields) {
$in{$key} = $add_system_fields{$key};
}
# Set date variable to today's date.
$in{$db_cols[$db_modified]} = &get_date; # Print out the validate input to a "validation database" where it is stored until
# the admin decides to add it into the real database.
open (VAL, ">>$db_valid_name") or &cgierr("error in add_record. unable to open validate file: $db_valid_name. Reason: $!");
flock(VAL, 2) unless (!$db_use_flock);
print VAL &join_encode(%in);
close VAL; # automatically removes file lock # Send the admin an email message notifying of new addition.
&send_email;
# Send the visitor to the success page.
&site_html_add_success;
} I split the sub in two, which is the key to keeping the submitted info in memory. The second sub takes the info and processes it as an addition to the validate database, and sends the email.
This is the sub in
site_html_templates.pl:
sub site_html_confirm_add {
# --------------------------------------------------------
# This routine is used to display what an add-confirm page should look like. &html_print_headers; print &load_template ('add_confirm.html', {
Category => $in{'Category'},
%in,
%globals
});
} Then add this to
add.html, just before the submit button code:
<input type="hidden" name="do" value="confirm" /> This goes in
add_confirm.html and in
add_error.html:
<input type="hidden" name="ID" value="<%ID%>" /> <input type="hidden" name="do" value="add" /> That should do it!
Leonard
aka PerlFlunkie