|
![Picture of Tarak Blah Picture of Tarak Blah](/graphics/unknown.gif) Tarak Blah - 2007-03-19 12:30:15
Hello,
I ask myself how to accomplish this:
I have two input-fields, one is called "SizeMinimum" and the other is called "SizeMaximum". Think about a search form as an example. These two fields can be integer- or float-values. It is obvious that the value given for the field "SizeMinimum" must be smaller than the one given in for the field "SizeMaximum" and vice versa. I can validate the fields themselves if they are correct, but I cannot check the condition described using the main class only. Is there a way to check if the fields are correct? I think about two functions called "ValidateAsSmallerThen" and "ValidateAsBiggerThen" with the respective names of the fields as argument. From my point of view there are a lot of situations where one could need this kind of validation...
Tarak
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2007-03-19 14:11:47 - In reply to message 1 from Tarak Blah
You can use ValidateMinimumLength for requiring a minimum size. You can set the MAXLENGTH attribute to limit the text value size. This way the browser will not let the user enter more text than it is allowed.
![Picture of Tarak Blah Picture of Tarak Blah](/graphics/unknown.gif) Tarak Blah - 2007-03-19 16:07:25 - In reply to message 2 from Manuel Lemos
I know that I can use these to validate the field itself. I meant that these are two separate input-fields of type text. Consider a form where one could search for a minimum and a maximum value of a size. Either the minimum or the maximum value is omitted or both fields are filled with values. In the latter case the maximum must of course be greater then the minimum value.
Here is some code to make it clear:
$form->AddInput(array(
"CLASS" => "InputText",
"ID" => "SizeMinimum",
"LABEL" => $_inputs['SizeMinimum']['Label'],
"LabelCLASS" => "SizeMinimum",
"LabelID" => "LabelSizeMinimum",
"LabelTITLE" => $_inputs['SizeMinimum']['Title'],
"MAXLENGTH" => $_inputs['SizeMinimum']['MaxLength'],
"NAME" => "SizeMinimum",
"TABINDEX" => $_inputs['SizeMinimum']['TabIndex'],
"TITLE" => $_inputs['SizeMinimum']['Title'],
"TYPE" => "text",
"ValidateAsInteger" => true,
"ValidateAsIntegerErrorMessage" => $_inputs['SizeMinimum']['ValidateAsIntegerErrorMessage'],
"ValidateErrorMessage" => $_inputs['SizeMinimum']['ValidateErrorMessage'],
"ValidationLowerLimit" => (int) 0,
"ValidateOptionalValue" => true,
"ValidationUpperLimit" => (int) 200
));
$form->AddInput(array(
"CLASS" => "InputText",
"ID" => "SizeMaximum",
"LABEL" => $_inputs['SizeMaximum']['Label'],
"LabelCLASS" => "SizeMaximum",
"LabelID" => "LabelSizeMaximum",
"LabelTITLE" => $_inputs['SizeMaximum']['Title'],
"MAXLENGTH" => $_inputs['SizeMaximum']['MaxLength'],
"NAME" => "SizeMaximum",
"TABINDEX" => $_inputs['SizeMaximum']['TabIndex'],
"TITLE" => $_inputs['SizeMaximum']['Title'],
"TYPE" => "text",
"ValidateAsInteger" => true,
"ValidateAsIntegerErrorMessage" => $_inputs['SizeMaximum']['ValidateAsIntegerErrorMessage'],
"ValidateErrorMessage" => $_inputs['SizeMaximum']['ValidateErrorMessage'],
"ValidationLowerLimit" => (int) 0,
"ValidateOptionalValue" => true,
"ValidationUpperLimit" => (int) 200
));
But what if the user gives in the following:
- In the "SizeMinimum"-input-field: 64
- In the "SizeMaximum"-input-field: 45
This would result in a strange query:
"SELECT FROM table WHERE SizeMinimum >= 64 AND SizeMaximum <= 45"
It's obvious that this query would never return a result...
I need to validate two different fields depending on each other's values, that's why I asked...
I would call these arguments for the AddInput-function "ValidateAsGreaterThan" and "ValidateAsLessThan" (better than stated above), and write my AddInput-argument like this:
$form->AddInput(array(
...
"ID" => "SizeMinimum",
...
"ValidateAsLessThan" => "SizeMaximum",
"ValidateAsLessThanErrorMessage" => "Please give in a value that is greater than the SizeMaximum"
));
$form->AddInput(array(
...
"ID" => "SizeMaximum",
...
"ValidateAsGreaterThan" => "SizeMinimum",
"ValidateAsLessThanErrorMessage" => "Please give in a value that is less than the SizeMinimum"
));
Actually this would make a lot of sense to me as I'm planning to develop at least 3 larger forms that should work like that. I know that I could validate this by a server-side function, but I already can see the few lines of javascript-code that would catch this error on the client-side. I hope not to be too demanding though... :-)
![Picture of Tarak Blah Picture of Tarak Blah](/graphics/unknown.gif) Tarak Blah - 2007-03-19 16:14:12 - In reply to message 3 from Tarak Blah
uups, stupid mistake... the example code must of course be:
$form->AddInput(array(
...
"ID" => "SizeMinimum",
...
"ValidateAsLessThan" => "SizeMaximum",
"ValidateAsLessThanErrorMessage" => "Please give in a value that is less than the SizeMaximum"
));
$form->AddInput(array(
...
"ID" => "SizeMaximum",
...
"ValidateAsGreaterThan" => "SizeMinimum",
"ValidateAsLessThanErrorMessage" => "Please give in a value that is greater than the SizeMaximum"
));
just too bad when one hits the submit- instead of the preview-button! sorry!
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2007-03-19 17:40:44 - In reply to message 3 from Tarak Blah
This is a very specific need. I recommend that you implement a custom validation plug-in to address that need.
Take a look at the form_custom_validation.php example plug-in class and the test_custom_validation.php example script to learn how to develop a custom validation plug-in adapted for your needs.
|