Page 1 of 1

forms class feature: OR field validation

Posted: Tue Jul 27, 2004 12:24 pm
by tripps
I'm trying to develop a ServerValidationFunction (unless one is already present or there's a workaround) which basically does an OR validation on two fields. For example, I've got two fields: business phone or evening phone.

Code: Select all

$registration->AddInput(array(
	"TYPE"=>"text",
	"NAME"=>"businessphone",
	"ID"=>"businessphone",
	"TABINDEX"=>18,
	"SIZE"=>30,
	"MAXLENGTH"=>30,
	"ValidateOnlyOnServerSide"=>1,
	"ValidateRegularExpression"=>"^[0-9]{3}([- \.])?[0-9]{3}([- \.])?[0-9]{4}$",
	"ValidateRegularExpressionErrorMessage"=>"Please enter a valid 10 digit phone number.",
	//"ValidateAsNotEmpty"=>1,
	//"ValidateAsNotEmptyErrorMessage"=>"Please enter your daytime phone number.",
	"LABEL"=>$registrationfields['businessphone']
));
$registration->AddInput(array(
	"TYPE"=>"text",
	"NAME"=>"eveningphone",
	"ID"=>"eveningphone",
	"TABINDEX"=>19,
	"SIZE"=>30,
	"MAXLENGTH"=>30,
	"ValidateOnlyOnServerSide"=>1,
	"ValidateRegularExpression"=>"^[0-9]{3}([- \.])?[0-9]{3}([- \.])?[0-9]{4}$",
	"ValidateRegularExpressionErrorMessage"=>"Please enter a valid 10 digit phone number.",
	//"ValidateAsDifferentFrom"=>"businessphone",
	//"ValidateAsDifferentFromErrorMessage"=>"You must enter in at least one contact phoner number."
	//"ValidateAsNotEmpty"=>1,
	//"ValidateAsNotEmptyErrorMessage"=>"Please enter your evening phone number.",
	"LABEL"=>$registrationfields['eveningphone']
));
As you can see, I've got a number of lines commented out as I've tried to find something that works. What I would like to have happen is for at least one of the fields has a valid number. It can be either, or both, but at least one must contain a number. Take a look at my post on regex vs. empty fields here as well for a related topic. Anyone have any suggestions as to how to begin? TIA!

Re: forms class feature: OR field validation

Posted: Tue Jul 27, 2004 11:06 pm
by mlemos
tripps wrote:I'm trying to develop a ServerValidationFunction (unless one is already present or there's a workaround) which basically does an OR validation on two fields. For example, I've got two fields: business phone or evening phone.
You need to use the forms class GetInputValue function to get the other field value check it. Since the class does not pass a reference to its current object, I am afraid you need to pass it via a global variable. This is not nice but it solves your problem.

A nicer way is to develop a custom input class that you can plug-in and perform those special types of validation logic. It is more complicated but it may be worth the effort if you intend to use that kind of validation logic multiple times in your application.