-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FormHelper appends ID to explicitly defined URL #11794
Comments
This unfortunately is expected behavior and there are tests for it. But it is indeed wacky hidden automagic which should be changed in 3.6. |
How do we go about removing the current behavior without breaking existing applications? Removing the id addition seems like the kind off thing that would break userland code. |
Guess so, in 4.0 then. |
In the meantime, noting this behavior in the documentation might prevent some confusion for 3.x users. Perhaps just a "To prevent your entity's ID from being appended to the URL supplied |
@PhantomWatson Sounds good, can you please open a PR on the docs repo for the same? |
Avoids this issue, which causes the user ID to be automatically appended to the end of the URL, e.g. /users/my-account/123: cakephp/cakephp#11794
Added to roadmap as part of cleanup task: https://github.com/cakephp/cakephp/wiki/4.0-Roadmap#cleanup-tasks |
This is a: bug
CakePHP Version: Tested with 3.5.8, but the relevant code appears identical in the latest version (3.6.0-beta1)
What I did
On
/users/my-account
...What happened
<form method="post" accept-charset="utf-8" action="/users/my-account/123">
<- ID appendedWhat I expected to happen
<form method="post" accept-charset="utf-8" action="/users/my-account">
Cause
FormHelper::_formUrl()
modifies the value of$options['url']
by appending the current record's ID if$options['url']['_name']
is unspecified and no other numerically-indexed parameters are passed.In an application I'm reviewing, this has the effect of the form on
/users/my-account
submitting to/users/my-account/$userId
, despite explicitly setting the URL without an ID in$this->Form->create()
.Recommendation
&& isset($options['url']['_name']
from the condition beforereturn $options['url'];
, as requiring a route name seems kind of arbitrary.Router::url()
so it gets passed as a string.The text was updated successfully, but these errors were encountered: