Issue
I have an application in Symfony with tabs and load asynchronous with Ajax, so that I can use two forms in the application at a time. I have a form to register users and another to update user data. In the update form, Symfony2 generated form therethrough to create users (UserType), so the id of the elements of forms are the same.
On the other hand I have a function to validate form elements, but when it validates one of these forms, validates the other also to have the same id elements, so no validating each form done right.
For example, using Twig
{{form_row (edit_form.name)}}
generates me an input with id = "user_name"
and I need to modify it to the update form as id = "update_user_name"
.
Is there any way to change the id attribute in that time?
Solution
You can do this:
{{ form_row(edit_form.name, { 'id': 'edit_user_name' }) }}
If you want get the original id and prefix it, you can try this:
{{ form_row(edit_form.name, { 'id': 'update_' ~ edit_form.name.vars.id }) }}
Hope this suits your need.
Answered By - chalasr
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.