Purpose: Manage an HTML checkbox item
Members:
valueName - if there is an initial state for the checkbox, say, for instance, a Y or N value read in from a database, this member should be set to the name of that value.
defaultState - set to either "on" or "off". The default for this one is "off"
checkBoxOnValue - is defaulted to "Y". Override it in a descendant if you want it to be something else.
checkBoxOffValue - is defaulted to "N". Override it in a descendant if you want it to be something else.
Methods:
There are no special methods specific to this class. Commonly, the setup method is extended for any special initial state for the checkbox.
Overlays:
An overlay for the checkbox should exist in the template overlays file for the SnapOn, and referenced by the template member variable. For an example, below is the syntax for the overlay for the Post Comments Allowed checkbox. It's important that the checkbox have a name, and notice the _@checked@_ parameter.
<input type=checkbox name=comments_allowed_flag _@checked@_ /> Allow Comments on this post
Example:
Below is the code for the check box in the Post form that determines whether comments will be allowed for the post. Notice that the setup method is extended because the checkbox has to read the comments_allowed_default setting to get an initial state.
Notice: it's very important that the parent::setup( ) method be called, as it performs important functions for the checkbox in the ancestor. Of course, that's good practice in all cases where one of the Phoo classes is extended.
class PostCheckBoxCommentsAllowed extends PhooCheckBox {
var $name = "PostCheckBoxCommentsAllowed";
var $securityRole = ROLE_POSTER;
var $template = "=|Post.checkbox.comments_allowed|=";
var $valueName = "comments_allowed_flag";
function setup( ) {
/* set the default state */
$commentsAllowedDefault = $this->session->getSetting( "comments_allowed_default" );
if ( $commentsAllowedDefault == "Y" ) {
$this->defaultState = "on";
}
else {
$this->defaultState = "off";
}
parent::setup( );
}
}