cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[NFR] Embedded Forms

Open mitris opened this issue 13 years ago • 21 comments

http://symfony.com/doc/current/book/forms.html#embedded-forms

mitris avatar Jun 17 '13 22:06 mitris

A NFR cannot be posted with a simple link, please follow this NFR guide: https://docs.phalconphp.com/en/latest/new-feature-request

phalcon avatar Jun 17 '13 22:06 phalcon

Ok, I can try to explain this feature. In some cases we need create more one object from submitted user data. Exapmples:

  1. User creates ticket and he saw form with fields which refers to the ticket and message.
  2. User register on the site, and form contains field from two models profiles and users.
  3. 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';
}

mitris avatar Jun 18 '13 07:06 mitris

+1 this idea is very useful

kolypto avatar Feb 09 '14 00:02 kolypto

I agree

valVk avatar Apr 15 '15 22:04 valVk

Up?

valVk avatar Aug 10 '15 20:08 valVk

+1

googlle avatar Mar 23 '16 16:03 googlle

+1, something is going on with this feature?

deoomen avatar Dec 01 '17 13:12 deoomen

+1

pgeimer avatar Feb 05 '18 12:02 pgeimer

+1

cchyzyk avatar Feb 05 '18 13:02 cchyzyk

+1 in 5 years after...

sergii-okhotnyi avatar Mar 18 '18 16:03 sergii-okhotnyi

Still relevant.

StudioMaX avatar Jun 16 '18 17:06 StudioMaX

Still relevant.

StudioMaX avatar Sep 14 '18 20:09 StudioMaX

Still relevant.

StudioMaX avatar Dec 14 '18 05:12 StudioMaX

Closing in favor of phalcon/cphalcon#13855. Will revisit if the community votes for it, or in later versions.

niden avatar Feb 23 '19 23:02 niden

Bump

StudioMaX avatar Jun 10 '19 05:06 StudioMaX

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.

diegosardina avatar Jul 03 '19 14:07 diegosardina

Still relevant

StudioMaX avatar Apr 20 '22 06:04 StudioMaX

Planning this for v7 with a Forms overhaul

niden avatar Jun 10 '26 16:06 niden

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\Manager runs listeners with equal priority in undefined order (SplPriorityQueue).
  • TagFactory input helpers are cached stateful singletons (Input\Select::selected() is never reset), which breaks rendering the same widget twice in one request.
  • The committed ext/ on 7.0.x is stale against the .zep sources (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 avatar Oct 15 '26 21:10 Izopi4a

@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.

niden avatar Oct 15 '26 21:10 niden