* @copyright (c) 2006 - 2016 Stefan Gabos * @package Controls */ class Zebra_Form_Image extends Zebra_Form_Control { /** * Adds an control to the form. * * Do not instantiate this class directly! Use the {@link Zebra_Form::add() add()} method instead! * * * // create a new form * $form = new Zebra_Form('my_form'); * * // add an image control to the form * $obj = $form->add('image', 'my_image', 'path/to/image'); * * // don't forget to always call this method before rendering the form * if ($form->validate()) { * // put code here * } * * // output the form using an automatically generated template * $form->render(); * * * @param string $id Unique name to identify the control in the form. * * The control's name attribute will be the same as the id attribute! * * This is the name to be used when referring to the control's value in the * POST/GET superglobals, after the form is submitted. * * This is also the name of the variable to be used in custom template files, in * order to display the control. * * * // in a template file, in order to print the generated HTML * // for a control named "my_image", one would use: * echo $my_image; * * * @param string $src (Optional) Path to an image file. * * @param array $attributes (Optional) An array of attributes valid for * {@link http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.4 input} * controls (size, readonly, style, etc) * * Must be specified as an associative array, in the form of attribute => value. * * // setting the "alt" attribute * $obj = $form->add( * 'image', * 'my_image', * 'path/to/image', * array( * 'alt' => 'Click to submit form' * ) * ); * * * See {@link Zebra_Form_Control::set_attributes() set_attributes()} on how to set * attributes, other than through the constructor. * * The following attributes are automatically set when the control is created and * should not be altered manually:
* * type, id, name, src, class * * @return void */ function __construct($id, $src, $attributes = '') { // call the constructor of the parent class parent::__construct(); // set the private attributes of this control // these attributes are private for this control and are for internal use only // and will not be rendered by the _render_attributes() method $this->private_attributes = array( 'disable_xss_filters', 'locked', ); // set the default attributes for the image control // put them in the order you'd like them rendered $this->set_attributes( array( 'alt' => $id, 'class' => 'image', 'id' => $id, 'name' => $id, 'src' => $src, 'type' => 'image', ) ); // if "class" is amongst user specified attributes if (is_array($attributes) && isset($attributes['class'])) { // we need to set the "class" attribute like this, so it doesn't overwrite previous values $this->set_attributes(array('class' => $attributes['class']), false); // make sure we don't set it again below unset($attributes['class']); } // sets user specified attributes for the table cell $this->set_attributes($attributes); } /** * Generates the control's HTML code. * * This method is automatically called by the {@link Zebra_Form::render() render()} method! * * @return string The control's HTML code */ function toHTML() { return '_render_attributes() . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '>'; } } ?>