简体   繁体   English

symfony获取表单属性

[英]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. 我知道这是一个愚蠢的问题,但我需要知道我可以通过PHP获取表单窗口小部件属性我的意思不是值,而是id,类甚至父或子。 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? 如果不可能,那么如何在表单验证之前创建JS函数并将数组作为值发布到表单中?

<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. 是的,我可以获取值并将表单提交给JS,然后由JS获取所有属性,然后通过ajax将其发送给PHP处理程序。 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 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 : 您可以在模板中的表单字段上调用get()方法,例如,在form使用字段item

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

The class - only if set - can be retrieved like this: 该类 - 仅在设置时 - 可以像这样检索:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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