Jump to:

1969 Posts in 1272 Topics by 606 members

Form Questions

SilverStripe Forums » Form Questions » SS3 - Front end UploadField issue

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

Page: 1
Go to End
Author Topic: 334 Views
  • Spambanjo
    Avatar
    Community Member
    14 Posts

    SS3 - Front end UploadField issue Link to this post

    I'm having a problem with a front end UploadField.

    I am creating a large SiteConfig extension module designed to give added functionality to various collections of general information such as people, email addresses, telephone numbers, etc, using individual data objects for each element. I then have, for example, a contact page type which lists people, telephone, etc, assigned to the site config.

    I have added a $has_one = array('Person'=>'Person') relationship to member. Person then $has_one = array('Image'=>'Image') which is working fine from the CMS. I'm now trying to create a the field on a front end form of my new FrontEndMembers module to allow members to edit their avatar image.

    I've stripped everything down to a bare minimum figure this out. I'm currently getting a "SyntaxError: JSON.parse: unexpected character" error on the field when I try to upload.

    Here's the code for the Member and Person:

    class Person extends DataObject {
    static $has_one = array(
    'Image' => 'Image'
    );
    }
    class MembersMemberExt extends DataExtension {
    static $has_one = array(
    'Person' => 'Person'
    );
    }

    And the form:

    class MemberPage_Controller extends Page_Controller {
    public function Form(){
    if($m=Member::currentUser()){
    if($this->urlParams['Action']=='image'){
    $f = new FieldList();
    $pf = new UploadField('Image','Image',$m->Person()->Image()) ;
    $pf->setConfig('allowedMaxFileNumber', 1);
    $pf->setRecord($m->Person());
    $path = preg_replace('/^' . ASSETS_DIR . '\//', '', 'UserUploads/' . $m->ID);
    $pf->setFolderName($path);
    $pf->setCanAttachExisting(false);
    $pf->setCanPreviewFolder(false);
    $pf->setCanUpload(true);
    $pf->setTitle('Image');
    $pf->getValidator()->setAllowedExtensions(array('gif','jpg','png','jpeg'));
    $f->push($pf);
    $a = new FieldList(
    new FormAction('saveimage', 'Save')
    );
    return new Form($this, 'saveimage', $f, $a);
    }
    } else {
    // ...
    }
    } else {
    // ...
    }
    }

    I've done a lot of Googlging and looked at other similar problems but I just can't see where I'm going wrong. I'm going to revert to a FileField for now so that I can continue the project but I would love to get this working ideally, so any help would be appreciated.

    Cheers.

  • Spambanjo
    Avatar
    Community Member
    14 Posts

    Re: SS3 - Front end UploadField issue Link to this post

    Is there anywhere else I can go to get help with this? I assumed the official forum would be the obvious choice but I never seem to get any responses when I ask questions.

    This should be simple

    334 Views
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.