Version: current

     1 <?php
     2 /**
     3  * Action that uses an image instead of a button
     4  * @package forms
     5  * @subpackage actions
     6  */
     7 class ImageFormAction extends FormAction {
     8     protected $image, $hoverImage, $className;
     9
    10     /**
    11      * Create a new action button.
    12      * @param action The method to call when the button is clicked
    13      * @param title The label on the button
    14      * @param image The default image to display
    15      * @param hoverImage The image to display on hover
    16      * @param form The parent form, auto-set when the field is placed inside a form
    17      */
    18     function __construct($action, $title = "", $image = "", $hoverImage = null, $className = null, $form = null) {
    19         $this->image = $image;
    20         $this->hoverImage = $hoverImage;
    21         $this->className = $className;
    22         parent::__construct($action, $title, $form);
    23     }
    24     function Field() {
    25         Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
    26         Requirements::javascript(SAPPHIRE_DIR . '/javascript/ImageFormAction.js');
    27
    28         $classClause = '';
    29         if($this->className) $classClause = $this->className . ' ';
    30         if($this->hoverImage) $classClause .= 'rollover ';
    31         return "<input class=\"{$classClause}action\" id=\"" . $this->id() . "\" type=\"image\" name=\"{$this->name}\" src=\"{$this->image}\" title=\"{$this->title}\" alt=\"{$this->title}\" />";
    32     }
    33 }
    34
    35 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -