Hi,
I'm trying to create a upload field in a Form class. The form is linked to a Dataobject which also contains images.
What I want is that user can login on the frontend to edit their assets.
I can show the image in the form and the other data, but I cannot change a image or upload an image.
I get the next error: [User Warning] Form::loadDataFrom() not passed an array or an object
Class "EditPage"
public function edit(SS_HTTPRequest $request) {
$Member = Member::currentUser();
$Params = $this->getURLParams();
$ID = Convert::raw2sql($Params['ID']);
if($Product = Woningen::get()->filter(array('MemberID' => $Member->ID))->byID($ID))
{
$Data = array(
'Woning' => $Product,
'FormEditWoning' => $this->FormEditWoning(),
);
return $this->customise($Data)->renderWith(array('BeheerEditWoning', 'Page'));
} else {
return $this->httpError(404, 'Sorry that product could not be found');
}
}
public function FormEditWoning() {
$form = new FormEditWoning($this, 'FormEditWoning');
$form->loadDataFrom($this->getCurrentProduct());
return $form;
}
public function getCurrentProduct()
{
$Params = $this->getURLParams();
$URLSegment = Convert::raw2sql($Params['ID']);
$member = Member::currentUser();
if($URLSegment && $Product = Woningen::get()->filter(array('MemberID' => $member->ID))->byID($URLSegment))
{
return $Product;
}
}
The form class:
class FormEditWoning extends Form {
public function __construct($controller, $name) {
$fields = new FieldList(
TextField::create("Title")->addExtraClass('form-control'),
TextField::create("Address")->addExtraClass('form-control'),
TextField::create("Postcode")->addExtraClass('form-control'),
TextField::create("City")->addExtraClass('form-control'),
TextField::create("Contact")->setAttribute('type', 'tel')->addExtraClass('form-control'),
TextField::create("Website")->addExtraClass('form-control'),
TextField::create('Price')->addExtraClass('form-control'),
HtmlEditorField::create("Description")->addExtraClass('form-control'),
DropdownField::create('TV', '', singleton('Woningen')->dbObject('TV')->enumValues())->addExtraClass('form-control'),
DropdownField::create('CD', '', singleton('Woningen')->dbObject('CD')->enumValues())->addExtraClass('form-control'),
UploadField::create('Photo')->setCanAttachExisting(false)->setCanPreviewFolder(false)->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')),
UploadField::create("Photo1")->setCanAttachExisting(false)->setCanPreviewFolder(false)->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')),
UploadField::create("Photo2")->setCanAttachExisting(false)->setCanPreviewFolder(false)->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')),
HiddenField::create('ID')
);
$validator = new RequiredFields('Naam', 'Email', 'Aankomst', 'Vertrek', 'Telefoon');
$actions = new FieldList(FormAction::create("submit")->setTitle("Save changes")->addExtraClass('btn btn-danger'));
parent::__construct($controller, $name, $fields, $actions, $validator);
}
Hopefully someone can help me.