Skip to content

Using the onSuccess and onFailure

Iltar van der Berg edited this page Nov 1, 2017 · 2 revisions

The onSuccess and onFailure callback can be used to process the submitted data. In the case that the data was valid (i.e., no form errors) the onSuccess will be called. If the form was submitted but the data wasn't valid, the onFailure will be called. This way it is possible to always handle the form.

The signature for both these callbacks is:

use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;

function (mixed $data, FormInterface $form, Request $request): void;

However, since these are callbacks and passing additional arguments is allowed in PHP you will most likely only need the $data parameter.

Clone this wiki locally