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.

Widgets /

Discuss SilverStripe Widgets.

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

Help for upload image using widget


Reply


970 Views

Avatar
webcook

Community Member, 20 Posts

6 June 2009 at 7:35pm

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(
"FileTypeID"
));
}

function doForm($data, $form) {
$file = new File();
$file->loadUploaded($_FILES['FileTypeID']);

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

thanks