http://docs.blesta.com/display/dev/Error+Checking has some erroneous information in it. Under the heading "Custom Rules" the documentation instructs the developer to create a function "getRules()"
getRules() may have been called to retrieve the rules for a custom field in previous versions, but it is no longer called. (I have not tested this in the present beta release.) Either getRules() needs to be called once again to retrieve those custom rules, or documentation should specify that the function validateService is the function that needs modification.
This is the way I modified validateService to include my rules. I added these lines immediately before the line $this->Input->setRules($rules);
The first parameter of rules, "hostname", identifies the variable the rule is for. The second parameter, e.g. "format" is an arbitrary name you are assigning to the rule. It must be unique within the scope of the variable. (That is, two variables can have a rule with the same name, but a single variable must have different names for all of its rules.)
$rules["hostname"]["format"] = array(
'pre_format' => array(array($this, "wrap_strtolower")), /* wrap_strtolower is a function in the same class as this function. It simply returns strtolower($inputstring) because strtolower() is not accessible as a callback function. The function returns a string which will be passed to the rule. */
'rule' => array("matches", "/^[a-z][a-z0-9]{2,31}$/"),
'message' => 'Hostname is incorrectly formatted. It must be between 3 and 32 characters. It must begin with a letter and contain only letters, numbers, and dashes.',);
$rules["hostname"]["absent"] = array(
'pre_format' => array(array($this, "wrap_strtolower")),
'rule' => array(array($this, "validateAbsent"),), /* validateAbsent is a function in the same class as this function. It returns true if it finds that its input is valid, and false if not. */
'message' => "This hostname already exists.");
Directly setting $rules to an array as recommended by the documentation should be considered harmful because it will clobber any rules already set, such as checking that the field is required (if that was specified in the module configuration).
I've made this bug report verbose to assist anyone who was confused by the documentation.
Question
will
http://docs.blesta.com/display/dev/Error+Checking has some erroneous information in it. Under the heading "Custom Rules" the documentation instructs the developer to create a function "getRules()"
getRules() may have been called to retrieve the rules for a custom field in previous versions, but it is no longer called. (I have not tested this in the present beta release.) Either getRules() needs to be called once again to retrieve those custom rules, or documentation should specify that the function validateService is the function that needs modification.
This is the way I modified validateService to include my rules. I added these lines immediately before the line $this->Input->setRules($rules);
The first parameter of rules, "hostname", identifies the variable the rule is for. The second parameter, e.g. "format" is an arbitrary name you are assigning to the rule. It must be unique within the scope of the variable. (That is, two variables can have a rule with the same name, but a single variable must have different names for all of its rules.)
Directly setting $rules to an array as recommended by the documentation should be considered harmful because it will clobber any rules already set, such as checking that the field is required (if that was specified in the module configuration).
I've made this bug report verbose to assist anyone who was confused by the documentation.
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.