Jump to:

1971 Posts in 1275 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » SS3 ImageField / UploadField Problem

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

Page: 1 2
Go to End
Author Topic: 2549 Views
  • RobboDev
    Avatar
    Community Member
    20 Posts

    SS3 ImageField / UploadField Problem Link to this post

    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

  • RobboDev
    Avatar
    Community Member
    20 Posts

    Re: SS3 ImageField / UploadField Problem Link to this post

    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?

  • Jedateach
    Avatar
    Forum Moderator
    227 Posts

    Re: SS3 ImageField / UploadField Problem Link to this post

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

  • RobboDev
    Avatar
    Community Member
    20 Posts

    Re: SS3 ImageField / UploadField Problem Link to this post

    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.

  • dpde
    Avatar
    Community Member
    14 Posts

    Re: SS3 ImageField / UploadField Problem Link to this post

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

  • RobboDev
    Avatar
    Community Member
    20 Posts

    Re: SS3 ImageField / UploadField Problem Link to this post

    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.

  • RobboDev
    Avatar
    Community Member
    20 Posts

    Re: SS3 ImageField / UploadField Problem Link to this post

    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

  • Jedateach
    Avatar
    Forum Moderator
    227 Posts

    Re: SS3 ImageField / UploadField Problem Link to this post

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

    2549 Views
Page: 1 2
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.