Jump to:

796 Posts in 409 Topics by 304 members


SilverStripe Forums » Widgets » Help for upload image using widget

Discuss SilverStripe Widgets.

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

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

    Help for upload image using widget Link to this post

    Hi experts,,

    I wrote code for upload image using silverstripe widget...

    Using the below code to upload the image,, it does not showed in admin side..

    What is the error please advice me

    class FeaturedProductWidget extends Widget {
    static $db = array(
    "Name" => "Varchar(255)", //location of folder to upload files to
    "Description" => "Text", //landing page after user uploads image
             "ImageName" => "Varchar(255)"

    static $title = "Feature Product Upload";
    static $cmsTitle = "Feature Product Upload";
    static $description = "Display an Feature Product for upload.";

    function getCMSFields() {
    return new FieldSet(
    new TextField("Name", "Name of the product."),
    new Text("Description", "Description of the product."),
                      new HiddenField("ImageName", "Name of the product.")            

    function Form() {
    $controller = new FeaturedProductWidget_Controller($this);
    return $controller->Form();


    class FeaturedProductWidget_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() {
    if($this->widget()) return $this->class . '/' . $this->widget()->ID;
    else return $this->class . '/';
    function Form() {
    return new Form($this, "Form", new FieldSet(
    new SimpleImageField (
    $name = "FileTypeID",
    $title = "Upload your image"
    ), new FieldSet(
    // List the action buttons here - doform executes the function 'doform' below
    new FormAction("doForm", "Submit")

    // List the required fields here
    ), new RequiredFields(

    function doForm($data, $form) {
    $file = new File();

    // Redirect to a page thanking people for registering
    // Director::redirect($this->Redirect);


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.