how to build form_ajax() function with data-request-validate attribute

- 1 answer

Ad

I need to use the form_ajax twig function to build my opening form tag (I want to use this function to benefit from the security token)

So my correct tag in raw html is

<Form class = "participant" data-request = "onAddToBasket" data-request-validate id = "form-add-to-basket">

With form_ajax, I have this line that works

{{ form_ajax('onAddToBasket', { id: 'form-add-to-basket' }) }}

But now I have to add the data-request-validate attribute and I do not know how to do it (I did not find it in the documentation nor in the search engines)

I tried several random combo but obviously I can not invent the correct syntax by myself :-)

any idea ? thanks for help

Ad

Answer

Ad

You can add it the same way you added the id attribute.

{{ form_ajax('onAddToBasket', { id: 'form-add-to-basket', 'data-request-validate': true }) }}
Ad
source: stackoverflow.com
Ad