0

I created a custom fieldset for a ui_component form to add custom input structures. The problem is, that the inputs are not included in the POST values.

enter image description here

The input you see is just a simple element in the fieldset.phtml you see in the Block code. It has a custom name "test_input_data". I implemented the fieldset similar to the conditions fieldsets on sales rules. The form namespance is shipping_rule_form.

<fieldset name="conditions" sortOrder="20">
    <settings>
        <collapsible>true</collapsible>
        <label translate="true">Conditions</label>
    </settings>
    <container name="conditions_apply_to" sortOrder="10">
        <htmlContent name="html_content">
            <block name="conditions_apply_to" class="Company\Namespace\Block\Adminhtml\ShippingRule\Edit\Tab\Conditions" />
        </htmlContent>
    </container>
</fieldset>

In the Block i am adding the fieldset like this:

protected function _prepareForm()
{
    $model = $this->_coreRegistry->registry('current_shipping_rule');
    $form = $this->addTabToForm($model);
    $this->setForm($form);

    return parent::_prepareForm();
}

protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $formName = 'shipping_rule_form')
{
    if (!$model) {
        $id = $this->getRequest()->getParam('entity_id');
        $model = $this->_ruleFactory->create();
        $model->load($id);
    }
    $conditionsFieldSetId = 'shipping_rule_form_conditions';

    /** @var \Magento\Framework\Data\Form $form */
    $form = $this->_formFactory->create();
    $form->setHtmlIdPrefix('rule_');
    $renderer = $this->_rendererFieldset->setTemplate(
        'Remklov_ShippingRule::promo/fieldset.phtml'
    )->setFieldSetId(
        $conditionsFieldSetId
    );

    $fieldset = $form->addFieldset(
        $fieldsetId,
        [
            'legend' => __(
                'Apply the rule only to the products matched by the rule, if following conditions are met.'
            )
        ]
    )->setRule(
        $model
    )->setRenderer(
        $renderer
    );
    $fieldset->addField(
        'conditions',
        'text',
        [
            'name'           => 'conditions',
            'label'          => __('Conditions'),
            'title'          => __('Conditions'),
            'required'       => true,
            'data-form-part' => $formName
        ]
    );

    $form->setValues($model->getData());
    return $form;
}

When i do a print_r() on the getParams() in the Save-Controller, it just returns the data of the corresponding model, but not the custom input value. I also tried to add the conditions exactly like in the sales_rule_form.xml, but still nothing is posted.

I could not find out how the submit logic works here and where i maybe missed or need to add logic.

1

1 Answer 1

0

I found the answer in this post: Magento 2 : Form Ui Component doesn't submit field in the html content

I needed to add the data-form-part="shipping_rule_form" to all the inputs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.