[DACHCOM-Formbuilder] field values in container (fieldset)

Hi @solverat, another formbuilder question…

Having some trouble getting a form field value (in and event listener) from a field that is a Fieldset container. Here is the basis for what I have -

$this->form = $event->getForm();

    foreach($this->form->getData()->getFields() as $field) {
        if ($field instanceof FormFieldContainer) {
            foreach($field->getFields() as $groupedField) {
                $value = $this->form->getData()->getFieldValue($groupedField->getName());
            }
        } 
    }

The key part here being $this->form->getData()->getFieldValue($groupedField->getName());

This does not get the submitted data the way it does with a non-grouped (or container) field.

Can you shed some light on this? Thank you!

1 Like

+1 I also am having this issue.

UPDATE: This is how you access it, e.g. “general” fieldset > “fullName” field:

namespace AppBundle\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use FormBuilderBundle\Event\SubmissionEvent;
use FormBuilderBundle\FormBuilderEvents;
use FormBuilderBundle\Storage\FormInterface as FormBuilderFormInterface;

class EduFormListener implements EventSubscriberInterface
{
    /**
     * @inheritDoc
     */
    public static function getSubscribedEvents()
    {
        return [
            FormBuilderEvents::FORM_SUBMIT_SUCCESS => ['formSubmitSuccess'],
        ];
    }

    public function formSubmitSuccess(SubmissionEvent $event)
    {
        $request = $event->getRequest();
        $form = $event->getForm();
        /** @var FormBuilderFormInterface $data */
        $data = $form->getData();
        $formId = $data->getId();
        $formConfiguration = $event->getFormConfiguration();
        \Pimcore\Log\Simple::log('lovia', 'FORM SUBMIT id: ' . json_encode($formId, JSON_PRETTY_PRINT, 2));
        \Pimcore\Log\Simple::log('lovia', 'FORM SUBMIT fields: ' . json_encode($data->getFields(), JSON_PRETTY_PRINT, 2));
        $general = $data->getFieldValue('general');
        \Pimcore\Log\Simple::log('lovia', 'general=' . json_encode($general));
        \Pimcore\Log\Simple::log('lovia', 'fullName=' . $general[0]['fullName']);
    }
}

I’m not sure why the extra wrapper array (maybe for uniform access pattern compared to Repeater), but that’s it.