Gossamer Forum
Home : Products : Links 2.0 : Customization :

Validating records multi input

Quote Reply
Validating records multi input
Hi,
Anyone have an idea.
With reference to adding new records, I am attempting to add new records in stages.

However as I submit the first part of the form I get a status error validating the input.

While I require to retain the validation of input field how would I alter the
“sub validate_record” to accept the validation form in stages ??
ie the first part of the form Title URL etc would be input and validated, then the second part Name Category and Email.


Cheers for the time.

Norvin

Quote Reply
Re: Validating records multi input In reply to
You need to take out the &validate reference in the subroutine where you have people confirm their submission. You should only have the &validate reference in the sub process_form routine.

Regards,

Eliot Lee
Quote Reply
Re: Validating records multi input In reply to
Hi,
Cheers for the responce.

I see that you are saying to &validate the form once at the end. However I would need to validate each part of the form in the event that the first section might have a field empty.
Rather than having the user get to fill in all the parts of the input form only to be told at the end to start again, and fill the complete form.

Cheers

norvin

Quote Reply
Re: Validating records multi input In reply to
In Reply To:
However I would need to validate each part of the form in the event that the first section might have a field empty.
You can use your OWN error checking codes in the CONFIRMATION subroutine! Search this forum for $error chomp.

Regards,

Eliot Lee
Quote Reply
Re: Validating records multi input In reply to
Hi, Sorry to bother you chaps again, however I am unable to find anything on Error chomp in the form.
So I have attempted to edit the validate sub, with no luck.
How would I go about changing the Sub validate below to ONLY check the first 5 fields in the database, then to repeat this for the second part of the form, to validate fields 5 to 10 and so on for each part of the multi input form.
So I would have a sub validate for each of the form parts. ie sub validate1
sub validate2
etc

sub validate_record {
# --------------------------------------------------------
# Verifies that the information passed through the form and stored
# in %in matches a valid record. It checks first to see that if
# we are adding, that a duplicate ID key does not exist. It then
# checks to see that fields specified as not null are indeed not null,
# finally it checks against the reg expression given in the database
# definition.
#
my ($col, @input_err, $errstr, $err, $line, @lines, @data);
my (%rec) = @_;

if ($rec{'add_record'}) { # don't need to worry about duplicate key if modifying
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
($data[$db_key_pos] eq $rec{$db_key}) and return "duplicate key error";
}
close DB;
}
foreach $col (@db_cols) {
if ($rec{$col} =~ /^\s*$/) { # entry is null or only whitespace
($db_not_null{$col}) and # entry is not allowed to be null.
push(@input_err, "$col (Can not be left blank)"); # so let's add it as an error
}
else { # else entry is not null.
($db_valid_types{$col} && !($rec{$col} =~ /$db_valid_types{$col}/)) and
push(@input_err, "$col (Invalid format)"); # but has failed validation.
(length($rec{$col}) > $db_lengths{$col}) and
push (@input_err, "$col (Too long. Max length: $db_lengths{$col})");
if ($db_sort{$col} eq "date") {
push (@input_err, "$col (Invalid date format)") unless &date_to_unix($rec{$col});
}
}
}
if ($#input_err+1 > 0) { # since there are errors, let's build
foreach $err (@input_err) { # a string listing the errors
$errstr .= "<li>$err"; # and return it.
}
return "<ul>$errstr</ul>";
}
else {
return "ok"; # no errors, return ok.
}
}

Thanks for the time
Norvin

Quote Reply
Re: Validating records multi input In reply to
Read the following Threads:

* http://www.gossamer-threads.com/...200&Old=allposts


* http://www.gossamer-threads.com/...200&Old=allposts

And next time, FOLLOW the instructions I posted in the Discussion
Forum on December 11,2000 for SEARCHING the forums.

I betcha you simply used the DEFAULT options in the SEARCH FORM, which don't do a darn thing most of the time!

Regards,

Eliot Lee