How to display custom FormBuilder error
Created 7 years ago by pepijn

I made a FormBuilder with a custom Handler. In the handler I'm importing a bunch of entries based on third party URL's. For some URL's, this process fails and I want to be able to flash a custom error message.

The code below doesn't produce any flash messages. What am I doing wrong?

    public function handle(FormBuilder $builder) {
        $urls = (array) $this->getUrls($builder);
        $result = $this->dispatch(new ImportEntries($urls));

        // this doesn't seem to work
        $builder->addFormError('somefield', 'some message');
        $builder->flash();
    }
ryanthompson  —  7 years ago

This is used in the front end via the form function? If so you don't need the flash there. That's probably wiping it before the FormController flashes it itself here: https://github.com/anomalylabs/streams-platform/blob/1.1/src/Http/Controller/FormController.php#L42

pepijn  —  7 years ago

@ryanthompson This is a FormBuilder for the admin (not used in frontend, no custom twig templates). When I remove the flash line, the flash messages are still not shown.

The handler is defined on the FormBuilder as follows:

protected $actions = [
        'import' => [
            'text' => 'Import',
            'type' => 'success',
            'handler' => ImportFormHandler::class,
        ]
    ];