codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
42 stars 24 forks source link

Function "setAction" or "setActionFromPageId" not working (PHP 8.2 / Contao 5.2) #215

Closed jaynoe closed 10 months ago

jaynoe commented 10 months ago

I created a FrontendModule Controller, where i build a custom form via the Form-Builder. Now i want to change the action value - but nothing happens. Here is the part of the code:

$form = new Form('donation_form_'.$model->id, 'POST');
$form->setActionFromPageId = PageModel::findById($model->jumpTo)->id;
$form->addContaoHiddenFields();
$form->addCaptchaFormField();

Also in PHP 8.2 you get a deprecated notice by using the setAction: or setActionFromPageId function: Property declared dynamically, this is deprecated starting from PHP 8.2

But i guess the functions should work despite the deprecated note. Also you can set a attribute to prevent the notice - just for information

qzminski commented 10 months ago

You should use a function like described here: https://github.com/codefog/contao-haste/blob/main/docs/Form.md#preparing-a-form-instance

$form->setActionFromPageId($model->jumpTo);
jaynoe commented 10 months ago

Yeah, i was following the guide. I changed it to $form->setActionFromPageId = $model->jumpTo but the action is still the initial request uri.

Nevermind its working now, dont know why - i changed it to this:

form->setAction(PageModel::findById($model->jumpTo)->getFrontendUrl());
qzminski commented 10 months ago

It did not work because you tried to assign a non-existing property instead of using a function:

$form->setActionFromPageId = PageModel::findById($model->jumpTo)->id;

should become:

$form->setActionFromPageId(PageModel::findById($model->jumpTo)->id);

and even better:

$form->setActionFromPageId($model->jumpTo);