Field name=“action” changed to “_action” (

Petr Tvaroha
Member | 25
+
0
-

For info, it might be handy to someone. It's behaviour of nette/forms 2.4.9.

Form field with name=“action” is silently changed into name=“_action” and after submitting form, it's changed back to “action”.

If you want to use Ajax manualy, i.e. not using e.g. $(form).serialize(), you have to use {“_action” : ‘some_action’} in the Ajax call.

It took me some time to find out. I am upgrading from Nette 2.0 where it was behaving different way, without any internal changes.

Ondřej Kubíček
Member | 494
+
+1
-

no, you should not use name of form directly,

you should get a name like this:

{$presenter['formName']->getElementPrototype()->getAttribute('name')}
Petr Tvaroha
Member | 25
+
0
-

Well, yes, maybe I should, thank you for the hint.

However, I have and old application and I am using an old way when I do not render the form on the page. I have just raw HTML code with buttons with the name “action” and value “some_action” and onclick I send it via JQuery.post(url, {"action" : "some_action"}) and it is broken now.

I think that Nette should not do this or it should be stated in a changelog as a possible BC break. I could not find it anywhere and originaly wanted to submit a bug on github.

If I change my code to {"_action" : "some_action"}, can I trust Nette that it won't silently change again in the future? I do not think that any framework should do this.

Last edited by Petr Tvaroha (2018-12-02 17:24)

Ondřej Kubíček
Member | 494
+
0
-

Nette 2.0 is pretty old. There are many changes.

You should read migration articles step by step:
2.1
2.2
2.3
2.4

Petr Tvaroha
Member | 25
+
0
-

Thank you. I searched through migration articles as well as in the forum before.

In 2.4 I can see only: Internal parameter do is now sent via POST as _do to avoid a collision,

There is nothing about changing “action” into “_action” and this is the reason, why I wrote this post. For someone who would have the same problem as me in the future.

And I repeat that I feel, that if “action” is used as an internal parameter, it should be sent as “_action”, but the framework should not change someone else's form field names.

And maybe it is a bug…?

Last edited by Petr Tvaroha (2018-12-02 18:49)

David Grudl
Nette Core | 8228
+
+1
-

use Nette\Forms\Helpers::generateHtmlName() to convert form control name to HTML name.

Petr Tvaroha
Member | 25
+
0
-

thank you, should have found out by myself