Skip to content

Csrf fails on forms with $this->createForm method #2844

Open
@ahmedali5530

Description

@ahmedali5530

Describe Your Problem 🎯
I am using symfony live components and i have created a form using $this->createForm(FormType::class) method , form rendered perfectly except the csrf field, which is showing just a text csrf-token instead of actual value in field. Alternately when i use $this->createFormBuilder() the csrf field generate correct value. which results in invalid csrf value on form submission.

Shouldn't both methods produce same result?

field created using $this->createFormBuilder

<input type="hidden" id="form__token" name="form[_token]" data-controller="csrf-protection" value="0b245bf.pvV9UHqIBXQ3lXmBoL5q1VfFQkKgD-k9OF6G7mJVVcU.0p05Zi39YkVw4CvMlfBbjA2zABX6ap9TUm3cpwllA6bHoRcKSOd3OgHDMA">

Field created using $this->createForm(FormType::class)

<input type="hidden" id="group__token" name="group[_token]" data-controller="csrf-protection" value="csrf-token">

I am using

php 8.3
symfony 7.2
symfony/ux-live-component ^2.23
symfony/ux-turbo ^2.23
symfony/stimulus-bundle ^2.23

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions