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.