17691 Posts in 4607 Topics by 2180 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 493 Views |
-
Urgent help in form with widget

8 June 2009 at 7:16pm
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%20formplease 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();
}
}?>
| 493 Views | ||
|
Page:
1
|
Go to Top |

