A place for users and developers of the Xataface to discuss and receive support.
by ststoddard » Mon Nov 05, 2007 4:16 pm
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.
S. T. Stoddard
-
ststoddard
-
- Posts: 56
- Joined: Mon Nov 05, 2007 4:10 pm
- Location: Davis, CA
by shannah » Mon Nov 05, 2007 4:36 pm
Try passing $params by reference:
- Code: Select all
function location_code__validate(&$record,$value,&$params) { ...
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by inmisia » Tue Nov 06, 2007 2:36 am
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.)
-
inmisia
-
- Posts: 16
- Joined: Tue Nov 06, 2007 2:01 am
by shannah » Tue Nov 06, 2007 6:14 am
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.
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by inmisia » Tue Nov 06, 2007 6:24 am
Hi,
I have Comment it, but now there isn't error message when field is not valid
-
inmisia
-
- Posts: 16
- Joined: Tue Nov 06, 2007 2:01 am
by shannah » Tue Nov 06, 2007 8:26 am
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?
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by inmisia » Tue Nov 06, 2007 8:58 am
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
-
inmisia
-
- Posts: 16
- Joined: Tue Nov 06, 2007 2:01 am
by shannah » Tue Nov 06, 2007 10:37 am
Do you get this error when adding a new record, editing an existing record, or both?
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by inmisia » Wed Nov 07, 2007 4:04 am
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.
-
inmisia
-
- Posts: 16
- Joined: Tue Nov 06, 2007 2:01 am
by shannah » Wed Nov 07, 2007 3:13 pm
I can't seem to reproduce this behavior.
Stephen, can you confirm that you are still having problems with this one?
-Steve
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by inmisia » Fri Nov 09, 2007 4:39 am
Hi, and about second question? Is it possible validate a field using
a value from other form field?
-
inmisia
-
- Posts: 16
- Joined: Tue Nov 06, 2007 2:01 am
by shannah » Sat Nov 10, 2007 10:03 am
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')
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by inmisia » Mon Nov 12, 2007 12:34 am
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.
-
inmisia
-
- Posts: 16
- Joined: Tue Nov 06, 2007 2:01 am
by shannah » Mon Nov 12, 2007 5:46 am
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 }
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by inmisia » Tue Nov 13, 2007 2:53 am
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
-
inmisia
-
- Posts: 16
- Joined: Tue Nov 06, 2007 2:01 am
Return to Xataface Users
Who is online
Users browsing this forum: No registered users and 23 guests
|