Jump to:

23472 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Urgent help in form with widget

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 698 Views
  • webcook
    Community Member
    20 Posts

    Urgent help in form with widget Link to this post

    Hi experts,

    i need urgent help from you.

    I need to develop one widget .The widget having one SimpleImageField with form..

    I cant able to see the browse button.

    i create the widget with help of the below link..

    please advice me to get the browser button on my widget.

    here with attached my coding..


    * A widget showing a subscribe form for a newsletter
    class YourWidget extends Widget {
       // ... do your other normal widget stuff ...
       static $title = 'Name';
       static $cmsTitle = 'Description';
       static $description = 'Adds HTML content to the widget sidebar. <br />(Save and refresh the page if you cannot see the text editor field.)';
       function Title() {
          return $this->WidgetTitle ? $this->WidgetTitle : self::$title;
       function Form() {
          $controller = new YourWidget_Controller($this);
          return $controller->Form();

    * Controller supporting forms on widgets
    * Note: the widgets shouldn't be used on secure pages for private forms - that kind of security isn't implemented
    class YourWidget_Controller extends Controller {
       protected $widget;
       function __construct($widget = null) {
          if($widget) $this->widget = $widget;
       function widget() {
          if($this->widget) return $this->widget;
          else if(is_numeric($this->urlParams['ID'])) return $this->widget = DataObject::get_by_id('Widget', $this->urlParams['ID']);
          else user_error('No widget selected', E_USER_ERROR);
       function Link() {
          return $this->class;
       function Form() {
          // ... This can be whatever form you like ...
          $widgetform = new WidgetForm($this, 'Form', new FieldSet(
             // ... Put your fields in here ...
             new SimpleImageField (
           $name = "FileTypeID",
           $title = "Upload your FileType"
          ), new FieldSet(
             new FormAction('doAction', 'Submit')
          return $widgetform;
       function doAction($data, $form) {
          // ... Do your thing, just like a normal SilverStripe form

          // ... This is a good way of giving feedback to the user about the submission. A message will be shown above the form.

          $this->Form()->sessionMessage("Thanks for submitting my form", "good");


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.