开发者

set value for a field after the form is rendered in processForm

开发者 https://www.devze.com 2023-04-11 20:14 出处:网络
I want to set a userID while a form is processed in processForm, located in actions.class.php. The problem is, I have unset the userID field and somehow I can\'t set a value for that. I\'ve searched b

I want to set a userID while a form is processed in processForm, located in actions.class.php. The problem is, I have unset the userID field and somehow I can't set a value for that. I've searched but I couldn't find anything useful.

I don't want to set the value in a hidden field or something like this, since the userID isn't the only value I want to set. Some values are based开发者_开发问答 on the form request itself.

Thanks.


You can change fields right after the binding - for example this is in my processForm method

$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{
  $model = $form->save();
  $model->setField(value);
  $model->save();
}

Ensure you call the save() method else the changes wont be visible

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号