Page 1 of 2
fieldname__validate function

Posted:
Mon Nov 05, 2007 4:16 pm
by ststoddard
Hello, a question regarding the validate function. I attempted the following per the documentation:
- Code: Select all
function location_code__validate(&$record,$value,$params) {
$app =& Dataface_application::getInstance();
$auth =& Dataface_AuthenticationTool::getInstance();
if ( $value == 'test' ) {
$params['message'] = "no!";
return false;
}
}
As a test after failed attempts using a more complex validation condition. Basically, the message doesn't come through. I get the form back with the field highlighted and the message saying "Permission Denied".
Am I doing something wrong?
FYI Steve -- I had to re-register with the user forum as it wouldn't accept my old username.

Posted:
Mon Nov 05, 2007 4:36 pm
by shannah
Try passing $params by reference:
- Code: Select all
function location_code__validate(&$record,$value,&$params) {
...

Posted:
Tue Nov 06, 2007 2:36 am
by inmisia
HI,
I have same problems with:
- Code: Select all
function Valore__validate( &$record, $value, &$params){
if ( $value>10 or $value<0 ){
$params['message'] = "Valore non valido.";
return false;
} else
{
return true;
}
and pass &$params by reference.
I get this error:
Fatal error: [pear_error: message="Valore non valido." code=211 mode= level=notice prefix="" info="On line 77 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\Error.php in function printStackTrace()
On line 1447 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php in function permissionDenied(Valore non valido.)

Posted:
Tue Nov 06, 2007 6:14 am
by shannah
Yes.. this appears to be a bug. In Dataface/QuickForm.php around line 1447, you will find some code:
- Code: Select all
if ( !$this->_record->validate($fieldname, $value, $params) ){
return Dataface_Error::permissionDenied($params['message']);
}
Comment this out or remove it... that should fix the issue.

Posted:
Tue Nov 06, 2007 6:24 am
by inmisia
Hi,
I have Comment it, but now there isn't error message when field is not valid

Posted:
Tue Nov 06, 2007 8:26 am
by shannah
OK.. I have reviewed the source and run tests on it and it appears to be working fine for me with version 0.7.1.
Please undo the changes that I suggested earlier. That code is a good failsafe.
Which leads me to ask: which version of Dataface are you running?

Posted:
Tue Nov 06, 2007 8:58 am
by inmisia
Hi,
I'm using version 0.7.1. too, I get this error:
Fatal error: [pear_error: message="Valore non valido." code=211 mode= level=notice prefix="" info="On line 77 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\Error.php in function printStackTrace()
On line 1447 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php in function permissionDenied(Valore non valido.)
On line 1320 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php in function pushField(Valore)
On line 2016 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php in function push()
On line of file in function save(array(28,1,15,2007-11-13,Save,2,array(2),,edit,0,analisi,0,30,browse,Record successfully saved.
,)
On line 1608 of file E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\lib\HTML\QuickForm.php in function call_user_func(array(Dataface_QuickForm Object,save),array(28,1,15,2007-11-13,Save,2,array(2),,edit,0,analisi,0,30,browse,Record successfully saved.
,)
On line in E:\Programmi\OCS Inventory NG\xampp\htdocs\dataface\Dataface\QuickForm.php on line 2046

Posted:
Tue Nov 06, 2007 10:37 am
by shannah
Do you get this error when adding a new record, editing an existing record, or both?

Posted:
Wed Nov 07, 2007 4:04 am
by inmisia
HI,
I get this error in both case, I'm using XAMPP per Windows Version 1.5.1
with:Apache/2.2.0 (Win32),PHP/5.1.1
I have another question about validate, is posible view a value of another fields? Example with $record->val('IDtipoAnalisi'), but I have view a value from form.

Posted:
Wed Nov 07, 2007 3:13 pm
by shannah
I can't seem to reproduce this behavior.
Stephen, can you confirm that you are still having problems with this one?
-Steve

Posted:
Fri Nov 09, 2007 4:39 am
by inmisia
Hi, and about second question? Is it possible validate a field using
a value from other form field?

Posted:
Sat Nov 10, 2007 10:03 am
by shannah
Absolutely.
The first parameter to your validate method &$record is a Dataface_Record object of the current record.
You can get the value of any field using $record->val('fieldname')

Posted:
Mon Nov 12, 2007 12:34 am
by inmisia
Hi, I need to validate a field using e value on form, not in table.
Ex if validate run on insert, $record->val('fieldname') is void.

Posted:
Mon Nov 12, 2007 5:46 am
by shannah
Oh.. yes. For this you should just use the values in the $_POST array.
e.g.
- Code: Select all
if ($_POST['fieldname'] == 'somevalue'){
// do something ...
}
else {
// do somethine else
}

Posted:
Tue Nov 13, 2007 2:53 am
by inmisia
Hi, was come back!!
I try with XAMPP Version 1.6.4 for Windows XP Professional service pack 2
( * Apache HTTPD 2.2.6 + Openssl 0.9.8e
* MySQL 5.0.45
* PHP 5.2.4
* PHP 4.4.7
* phpMyAdmin 2.11.1
* Zend Optimizer 3.3.0 )
and I get same error:
Fatal error: [pear_error: message="Valore non valido. range:" code=211 mode= level=notice prefix="" info="On line 77 of file C:\xampp\htdocs\dataface\Dataface\Error.php in function printStackTrace()
On line 1447 of file C:\xampp\htdocs\dataface\Dataface\QuickForm.php in function permissionDenied(Valore non valido. range:)
On line 1320 of file C:\xampp\htdocs\dataface\Dataface\QuickForm.php in function pushField(Valore)
On line 2016 of file C:\xampp\htdocs\dataface\Dataface\QuickForm.php in function push()
On line of file in function save(array(28,1,45,2007-11-05,Save,3,array(3),,edit,0,analisi,0,30,browse,-action=edit&-cursor=0&-table=a)
On line 1608 of file C:\xampp\htdocs\dataface\lib\HTML\QuickForm.php in function call_user_func(array(Dataface_QuickForm Object,save),array(28,1,45,2007-11-05,Save,3,array(3),,edit,0,analisi,0,30,browse,-action=edit&-cursor=0&-table=a)
On line 103 of file C:\xampp\htdocs\dataface\actions\edit.php in function process(array(Dataface_QuickForm Object,save))
On l in C:\xampp\htdocs\dataface\Dataface\QuickForm.php on line 2046
What OS are you using? Linux? Next I will try with OpenSuse 10.3