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
Reply


11 Posts   3143 Views

Avatar
RobboDev

Community Member, 21 Posts

6 July 2012 at 2:15pm

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?

Cheers
Rob

Avatar
RobboDev

Community Member, 21 Posts

6 July 2012 at 2:20pm

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?

Avatar
Jedateach

Forum Moderator, 232 Posts

24 July 2012 at 4:54pm

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

Avatar
RobboDev

Community Member, 21 Posts

24 July 2012 at 5:11pm

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.

Avatar
dpde

Community Member, 14 Posts

24 July 2012 at 8:38pm

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

Avatar
RobboDev

Community Member, 21 Posts

24 July 2012 at 9:31pm

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->removeByName("Content");
$fields->removeByName("Moderated");
$fields->removeByName("AdvertiserID");
$fields->removeByName("Reported");

      
$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",
      $fields,
      $actions = new FieldList(
         // List the action buttons here
         new FormAction("placeAd", "Place Your Advert")
      ),
      $requiredFields = new RequiredFields(
         "Content"
         // List the required fields here: "Email", "FirstName"
      )
   );
   $Params = $this->getURLParams();
$URLSegment = Convert::raw2sql($Params['ID']);

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

And my placeAd() function has the following code:

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

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

}
$ad->write();
      
   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.

Avatar
RobboDev

Community Member, 21 Posts

29 July 2012 at 11:22pm

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:

15AhYGko4tVX2rXcg6A8GxeWoftfpUKvbM

Cheers Rob

Avatar
Jedateach

Forum Moderator, 232 Posts

29 July 2012 at 11:47pm

Hey Rob, I posted this ticket yesterday, see if it helps you. [url]http://open.silverstripe.org/ticket/7715[/url]

Go to Top