Hi experts,
This is my code to upload the image for my widget,
My problem was i cant able to see the browser button to upload the image.
In my widget must have three fields
1) title
2)description
3)image name.
How to add those (title,description&browser) fields in my widgets..
Please help me to solve this problem
class FeatureProductWidget extends Widget {
// ... do your other normal widget stuff ...
static $db = array(
'Name' => 'Varchar(255)',
'Description' => 'Text',
'IPath' => 'Varchar(255)'
);
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 getCMSFields() {
return new FieldSet(
new TextField("Name","Number of galleries to show (0 for All)"),
new TextareaField("Description","Number of galleries to show (0 for All)"),
new HiddenField("IPath","Number of galleries to show (0 for All)")
);
}
function Form() {
$controller = new FeatureProductWidget_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 FeatureProductWidget_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(
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();
}
}
class WidgetForm extends Form {
protected $widget;
static $url_handlers = array(
'POST $WidgetID' => 'httpSubmission',
'GET $WidgetID' => 'httpSubmission',
);
function FormAction(){
if($this->widget){
return parent::FormAction()."/".$this->widget->ID;
}
return parent::FormAction();
}
function setWidget($wgt){
if($wgt != null){
$this->widget = $wgt;
}
}
function getWidget(){
return $this->widget;
}
}