Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Checking for 'required' without connecting to db

Quote Reply
Checking for 'required' without connecting to db
Hi,

I'm working on a mod of add.cgi to accept details of paid review requests and to print out an application form to be sent in with a check.

It's not using the validate database because I'll be manually adding the record, so it's also not checking the required fields and allowing blank entires through, try it:

http://www.qango.com/...r/addurl.cgi?ID=2033
(Click on 'Guaranteed Site Review' button and leave some of the fields blank before confirming)

Is there a way I can identify a field as 'required' in the HTML of the form and have the script check it before going on to create the success output?

All the best
Shaun

Quote Reply
Re: Checking for 'required' without connecting to db In reply to
You'll have to create a routine &check_input that checks each of the fields you want checked for valid input, then returns the user to the add form if some are missing or invalid.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Checking for 'required' without connecting to db In reply to
Thanks pugdog,

Is that something like this:

if (($field_name == "") {
&site_html_error ( { error => "$field_name is empty", %in }, $dynamic);
return;
}

... am I in the right ball park?

All the best
Shaun

Quote Reply
Re: Checking for 'required' without connecting to db In reply to
I posted codes in the Links 2.0 Customization Forum awhile back that does what you are looking for...

Here they are again:

1) Add the following error-checking statement in either the sub process_form or other subs where data is entered:

Code:

if ($in->param('Fieldname') eq "") {
$error .= "You did not fill out Fieldname";
}


2) Then toward the end of the sub, add the following codes:

Code:

if ($error) {
chomp($error);
&site_html_add_failure({error => $error, %in}, $dynamic);
return;
}


That's it.

Regards,

Eliot Lee
Quote Reply
Re: Checking for 'required' without connecting to db In reply to
You might want to make an entire routine to check what is passed in, and set an error flag for each missing field. That way, you can put a red asterisk near each missing field.

Let's say you have 6 fields you want to make sure have a value in them. They are passed in $in

($in->{field} =~ regex) || ($in->{"error_field"} = 'invalid' && $error = 'true'); ## doesn't matter what you set it to.
($in->{field2} =~ regex) || ($in->{"error_field2"} = 'invalid' && $error = 'true'); ## doesn't matter what you set it to.
....


Then, at the end of the routine do a check for $error. If positive, you want to send back to the add template, and in the add template you want to do something like:

<%if error_field%><FONT COLOR=RED>*</FONT><%endif%>

where you want to notify the user.

Now, I just woke up, so I _THINK_ the logic gates above are right:

ie: if the first is true, ignore what's in the (), else do BOTH the last conditions.



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Checking for 'required' without connecting to db In reply to
Thanks you guys - helpful as ever Smile - I'll give it a try when I get the chance and see what I can make of it.

All the best
Shaun