0

I've got a form in Statamic, and I want to pass some data back to it on submission to show a nice 'All good' message, e.g:

return redirect()
    ->back()
    ->with(['form_success' => true]);

Unfortunately the template completely ignores the contents of ->with() in the template.

Is there a way to get it to listen to with, or is there another way of doing this?

Meep3D
  • 3,803
  • 4
  • 36
  • 55
  • 1
    Show your template; how are you trying to reference this `form_success` being sent from the redirect? `$form_success`? or `session()->get('form_success')`? One of those should work, the other will not (assuming Statamic hasn't modified that base Laravel functionality) – Tim Lewis Jan 17 '23 at 16:02
  • It's an antlers template. Adding {{ dump }} shows it's not set anywhere. I'll check the session though. – Meep3D Jan 17 '23 at 16:22
  • Ah, so Statamic doesn't use `blade` templates eh? Interesting, considering Statamic is built on top of Laravel. But yeah, in base Laravel, something like `view('index')->with(['var' => 'test'])` would make `$var` available in the view, while `back()->with(['var' => 'test'])` would make `session()->get('var')` available. I haven't worked with Statamic in _years_, so I don't know what's changed, if anything. – Tim Lewis Jan 17 '23 at 16:25
  • @TimLewis Somewhat late to the party, but you can use both Antlers and Blade templates in Statamic. Just name them *.antlers.html or *.blade.php. – espenlg Aug 18 '23 at 11:59

1 Answers1

0

Whenever you return like that from a POST route, I believe the with data is also available in the session.

So in Antlers, you should be able to do something like this:

{{ session:form_success }}

And to display something in your template depending on if form_success is available, you can do this:

{{ if {session:has key="form_success"} }}
    <p>Success!</p>
{{ /if }}

Hopefully this will work for you!

Duncan McClean
  • 130
  • 2
  • 11