Wednesday, February 9, 2022

[FIXED] get value attribute of hidden input field in symfony controller

Issue

I'm using Symfony 5 and php7.

{{ form_widget(form.groupTab) }}<input type="hidden" id="ce-participants__type" data-field="app_registration_group_type_form[groupTab]" value="0">

I want to get the value attribute within the hidden input field. It should return '0' as string.

In my controller I`ve tried following:

$groupTab = $form->get('groupTab')->getViewData();

but I always get an empty string as response => ''


Solution

First, your hidden field has no name attribute, so I'm not even sure you can get its value back.

You should create that field with the form builder, just as you do the groupTab field. Then you can get its value with $form->get('yourHiddenField')->getData().



Answered By - Saphir

No comments:

Post a Comment

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