PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 9, 2022

[FIXED] How modify the id of the elements of a form generated with Symfony2?

 March 09, 2022     symfony     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing