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.

Form Questions

SS3 ImageField / UploadField Problem

Go to End

11 Posts   2977 Views


6 July 2012 at 2:15pm Community Member, 21 Posts

Hi Guys, the new Silverstripe 3 image field looks great!

However I cant seem to get it working. I have been uploading images, then submitting my form, and when i print_r($data) from the form submission, all i seem to get out at the backend is the following:

"Pic" is the name

[Pic] => Array
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
=> 0

Can anyone help out?



6 July 2012 at 2:20pm Community Member, 21 Posts

BTW a look in the DB and assets folder shows that the images are actually being uploaded, however the problem is there is no link with my submitted form?


24 July 2012 at 4:54pm Forum Moderator, 227 Posts

I'm having the same problem. Did you manage to find a solution?


24 July 2012 at 5:11pm Community Member, 21 Posts

Ah shit! I came here excited that you might have a solution for me!

I thought it might be because the actual Object that I was joining the image to might not have been written to the DB and assigned an ID, so I have tried editing one that had already been built on the front end, and this still didn't work.

I'm banging my head against a wall with this problem with no help, perhaps it needs to go in the "Upgrading to SS3" section?

I'd pay someone to show me where i'm going wrong.


24 July 2012 at 8:38pm Community Member, 14 Posts

It would help if you show us some lines of your source code.


24 July 2012 at 9:31pm Community Member, 21 Posts

Good point!

OK my Advert DO has this:

public static $has_one = array(
   "Advertiser" => "Member",
   "Category" => "Category",
   "Pic" => "Image"

My AddAdvert function Form() has the following code:

public function Form() {
$fields = singleton('Advert')->getFrontEndFields();

$fields->add(new AdvertContentField("Content", "Advert Text"));

$categoryField = $fields->fieldByName("CategoryID");
      $categoryField->setEmptyString("General / No Category");

if (!Member::currentUser()) {
$fields->add(new RecaptchaField("recapture"));
$form = new Form(
      $controller = $this,
      $name = "Form",
      $actions = new FieldList(
         // List the action buttons here
         new FormAction("placeAd", "Place Your Advert")
      $requiredFields = new RequiredFields(
         // List the required fields here: "Email", "FirstName"
   $Params = $this->getURLParams();
$URLSegment = Convert::raw2sql($Params['ID']);

if($URLSegment && $advert = Advert::get()->byId($URLSegment))
   return $form;

And my placeAd() function has the following code:

public function placeAd($data, $form, $another) {
$form->saveInto($ad = new Advert());
   //$ad->Content = $data["Content"];
if ($curMember = Member::currentUser()){
$ad->AdvertiserID = $curMember->ID;

if ($data["CategoryID"]) {
$ad->CategoryID = $data["CategoryID"];
$category = Category::get()->byId($data["CategoryID"]);

   Session::set('info', 'Thanks for your submission');
   return $this->redirectBack();

obviously some debug statements in there, but i cant get any Pic information (IDs, Names anything) when the form is submitted.


29 July 2012 at 11:22pm Community Member, 21 Posts

Biggest downside to Silverstripe is the total lack of activity on these forums!

I think the ImageField is broken on the frontend. I'm not going to post a ticket, as it could still be my code.

I got my form working by using "FileField" instead of "ImageField" then BOOM worked instantly.

If my PAIN IN THE ASS has helped you, please donate me some Bitcoins at this address:


Cheers Rob


29 July 2012 at 11:47pm Forum Moderator, 227 Posts

Hey Rob, I posted this ticket yesterday, see if it helps you. [url][/url]

Go to Top