QuickForm Controller: More specific error message for addRule

From: Date: Thu, 05 Feb 2009 14:16:36 +0000
Subject: QuickForm Controller: More specific error message for addRule
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-29677@lists.php.net to get a copy of this message
I have rather general question: in addRule, I am expected to provide an error message printed to the user if validation fails. Is there a way to include in this message some variables computed at the validation stage? The purpose is to be more specific about the reason for the failure of my custom validation. Here is an example of a situation when I need this: in one of my pages created with QFC, the user is presented a selection list. The list represents a tree, valid selections are those which are in different tree branches. So I create my custom validation function and check user selection. If the function finds wrong relation between some user-selected options, I want to be a bit more specific in my error message and give the user the names of these wrongly selected options. I would imagine the following naive code: $tmp = "Option $this->parent is parent of option $this->child."; $this->addRule( 'id_option', $tmp, 'callback', array($this, 'checkHierarchy') ); and the checkHierarchy function sets the variables $this->parent and $this->child. However, this does not work as apparently the tmp var is computed before the validation takes place... Any help would be greatly appreciated. Igor

« previous php.pear.general (#29677) next »