Tek
Tek

Reputation: 3050

Dynamically modify forms in Symfony2 without Javascript?

I was reading the How to dynamically Generate Forms Based on user Data from the Symfony2 cook book.

I'm seeking functionality similar to the link above.

However, if I understand correctly it suggests to use AJAX to update the form.

Is this correct?

This example is desired functionality I'm seeking:

Step 1:

Form //Controller locationAction
 ________________
|
|
| Country Select 
|
| |Please select...|
|
|      ____
|     |Next|
 _______________

Expectations after Hitting Next

Step 2:

|
v

Form //Controller locationAction
 ________________
|
|
| Country Select 
|
|      |U.S.|
|
|  
|      State
|  |Please select ....| //List is displayed that corresponds to their selected country
|
|      ______
|     |Submit|
 _______________

After pushing submit

Is it possible to obtain the above result using Form Subscribers/Form Listeners alone in one form with no JavaScript?

Or do I need to use JavaScript/create a separate form?

Upvotes: 1

Views: 790

Answers (1)

qtuan
qtuan

Reputation: 687

However, if I understand correctly it suggests to use AJAX to update the form.

No it doesn't. You can just submit the form to the same action. After each step, it's a new request/response and the dynamic form generation is handled at server side, not by javascript.

And perhaps, dynamic-generation-for-submitted-forms is exactly your use case (it's another section on the same guide).

Upvotes: 1

Related Questions