我无法通过Silverstripe中的前端表单上传图片。我看过这个page上的例子,但它对我没有帮助。更新文本字段工作正常。我的代码发布在下面,我错过了什么?
public function ChecklistForm()
{
$checklist = Checklist::get()->byID($this->request->param('ID'));
$form = Form::create(
$this,
__FUNCTION__,
FieldList::create(
TextField::create('Object','')
->addExtraClass('form-control')
->setAttribute('placeholder','Object')
->setAttribute('value', $checklist->Object),
TextField::create('Contact','')
->addExtraClass('form-control')
->setAttribute('placeholder','Contact')
->setAttribute('value', $checklist->Contact),
TextField::create('Address','')
->addExtraClass('form-control')
->setAttribute('placeholder','Address')
->setAttribute('value', $checklist->Address),
HiddenField::create('ChecklistId','')
->setAttribute('value', $this->request->param('ID')),
UploadField::create('Images','Upload Images')
->setFolderName('checklist-images')
),
FieldList::create(
FormAction::create('handleChecklist','Update Checklist')
->setUseButtonTag(true)
->addExtraClass('btn btn-default-color btn-lg')
),
RequiredFields::create('Object','Contact','Address')
)
->addExtraClass('form-style');
return $form;
}
public function handleChecklist($data, $form)
{
$checklist = Checklist::get()->byID($data['ChecklistId']);
$checklist->Object = $data['Object'];
$checklist->Contact = $data['Contact'];
$checklist->Address = $data['Address'];
$form->saveInto($checklist);
$checklist->write();
$form->sessionMessage('Checklist has been updated!','good');
return $this->redirectBack();
}
答案 0 :(得分:0)
您之后错过了逗号:
HiddenField::create('ChecklistId','')
->setAttribute('value', $this->request->param('ID'))