[NFR] Embedded Forms
http://symfony.com/doc/current/book/forms.html#embedded-forms
A NFR cannot be posted with a simple link, please follow this NFR guide: https://docs.phalconphp.com/en/latest/new-feature-request
Ok, I can try to explain this feature. In some cases we need create more one object from submitted user data. Exapmples:
- User creates ticket and he saw form with fields which refers to the ticket and message.
- User register on the site, and form contains field from two models profiles and users.
- Multilingual forms. If I'm try to create news, and I want to add all supported languages content in one form.
use Phalcon\Forms\Form,
Phalcon\Forms\FormContainer,
Phalcon\Forms\Element\Text;
$noteForm = new Form();
$noteForm->add(new Text("note"));
$messageForm = new Form();
$messageForm->add(new Text("message"));
$messageForm->addFormContainer("notes", $noteForm);
$ticketForm = new Form();
$ticketForm->add(new Text("title"));
$ticketForm->addFormContainer("messages", $messageForm);
Html element, rendered by following code such as:
<input type="text" name="title" />
<input type="text" name="messages[message]" />
<input type="text" name="messages[notes][note]" />
In action:
$ticket = new Ticket();
if ($ticketForm->isValid()) {
$ticket->save();
// $ticket object has related models such as message
// $ticket->messages[0]->message = ''some message';
// and message object has his relations
// $ticket->messages[0]->notes[0]->note = ''some note';
}
+1 this idea is very useful
I agree
Up?
+1
+1, something is going on with this feature?
+1
+1
+1 in 5 years after...
Still relevant.
Still relevant.
Still relevant.
Closing in favor of phalcon/cphalcon#13855. Will revisit if the community votes for it, or in later versions.
Bump
In my opinion the proposal that has been shown here phalcon/cphalcon#11579 is very elegant in the case of the embedding of a form collection and could be also taken in consideration.
It may be generalized in having Element\Form that embeds just one form and Element\Collection that embeds a collection of forms.
Although ideally it should receive a Form but the former approach is simpler and doesn't require an interface change.
Still relevant
Planning this for v7 with a Forms overhaul
Hi @niden ,
I couldn't find whether the Forms overhaul for v7 is already planned in detail or started, so I drafted an RFC for it, with Claude Code assisting:
https://github.com/Izopi4a/cphalcon/blob/T17106-forms-overhaul/resources/rfc/17106-forms-rfc.md
The design is inspired by Symfony Forms. The RFC keeps that architecture and vocabulary but builds it from Phalcon's own parts (Filter\Validation, Events, TagFactory + Volt, the new Container, Security), with the parts that only make sense inside Symfony's ecosystem left out. It is written in the same shape as your #17053 / #17054 NFRs: Problem, why rewrite vs fix, proposed approach, milestones, BC, open questions.
To validate the design before writing any Zephir, there is a plain-PHP prototype of milestone 1 next to the RFC (resources/rfc/prototype/, 253 tests). It runs against the built extension, so it uses the real Events\Manager, TagFactory, Http\Request and ORM. It covers the exact nesting from this issue (ticket[messages][0][notes][0][note]), a CollectionType, a ModelType that takes find() parameters and gives back model instances, and a renderer producing HTML through TagFactory. The prototype is only there to prove the API and life cycle; the plan is to port it to Zephir in PR-sized slices once the design is agreed.
Three things came up while prototyping that affect more than forms, and might be worth their own issues:
Events\Managerruns listeners with equal priority in undefined order (SplPriorityQueue).TagFactoryinput helpers are cached stateful singletons (Input\Select::selected()is never reset), which breaks rendering the same widget twice in one request.- The committed
ext/on7.0.xis stale against the.zepsources (e.g.Volt\Compiler::setOptions()returns null in the built extension).
Questions for you, also listed at the end of the RFC: new Phalcon\Form namespace next to a deprecated Phalcon\Forms, or replace in place? Is a Zephir default theme with Volt themes as overrides acceptable? Should Filter\Validation get nested-path support first? And does any of this collide with what you have in mind for #17053 / #17054?
Happy to adjust the RFC in whatever direction you prefer before any code goes further.
@Izopi4a Thanks. I will check it out. I have a full plan set up for the forms (subforms, validation and all that) so that will be coming your way so that we can align effort.
As I mentioned in your PR we will have to wait just a bit for v6 to be released and v5 to "freeze" so that we don't try and fix a moving target.