modir / laminas-book

0 stars 1 forks source link

Form independent of application #1

Open modir opened 10 months ago

modir commented 10 months ago

Comment from Froschdesign in the forum:

The forms and input filters in the book are independent of the application. This means that standard and custom validators, filters or form elements that require a database adapter or some other preparation for creation cannot be used.

Decision to make: Replace the current chapter or extend it?

froschdesign commented 10 months ago

Replace the current chapter or extend it?

Extending will not be enough, rewriting is the right way here.

Example:

https://github.com/modir/laminas-book/blob/6f20e597c948c7b43ab8c989276720898b26e7d6/docs/forms.md?plain=1#L540-L557

modir commented 10 months ago

Thank you very much for the valuable feedback. I will change this in the evening.

froschdesign commented 10 months ago

The methods addElements and addInputFilter are not needed. These customs methods can be replaced with the init method and by implementing the interface Laminas\InputFilter\InputFilterProviderInterface.

modir commented 10 months ago
* defining the `action` attribute is incorrect here, because there is no URL helper available; the URL helper is available in a controller or view script, so set it there

He was writing about this attribute: https://wiki.selfhtml.org/wiki/HTML/Attribute/action Which can be set there. Yes, it would probably be nicer if it is done in a controller, but it is not a must.

froschdesign commented 10 months ago

Yes, it would probably be nicer if it is done in a controller, but it is not a must.

Unfortunately, you are overlooking the crucial point: if the route is changed from contactus to contact, the action is wrong and no longer works.

https://github.com/modir/laminas-book/blob/6f20e597c948c7b43ab8c989276720898b26e7d6/docs/forms.md?plain=1#L411-L421

If the controller plugin Url or the view helper Url is used then router assemble the correct target. This means you do not need to update several places in the application and therefore the helpers for URL creation should always be used.