Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Urgent help in form with widget


Go to End


1629 Views

Avatar
webcook

Community Member, 20 Posts

8 June 2009 at 7:16pm

Edited: 08/06/2009 7:25pm

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..
http://doc.silverstripe.com/doku.php?id=widgets:forms&s=widget%20form

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

here with attached my coding..

<?php

/**
* 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')
));
$widgetform->setWidget($this->widget);
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");
Director::redirectBack();
}
}

?>
in admin side my widget show empty.like this

Attached Files