简体   繁体   中英

symfony get form attributes

I know that it is dumb question to ask but I need to know can I get form widget attributes through PHP I mean not a value but id, class or even parent or child. If I set them.

<label name = '{{ item.modulePath }}' id = 'main' class = 'menu_label' **parent = ''** **childs = ''**>{{ item.modulePath }}</label>

If it is not possible then how can I make JS function before form validation and post array to the form as value?

<form action="{{ path('menu_manage') }}" method="post">

Yes I could get values and submit form to JS and then by JS get all attributes and then through ajax send it to a PHP handler. But it would be longer, because I will need to include all components that have this action to the handle information to place where I need it.

Here is an example how to realize it

http://symfony2forum.org/threads/5-Using-Symfony2-jQuery-and-Ajax

You can call get() method on form field in template, eg having a form in form with field item :

{{ form.item.get('id') }}

The class - only if set - can be retrieved like this:

{{ form.item.get('attr').class }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM