XF 2.2 Return and break out of AJAX

Parsnip

Active member
How can I "break out" of AJAX when returning to a template after submitting from a form using ajax="true"?

I'm showing brief pop-up/slide-down error message phrases similar to the built-in search with AJAX, but when returning to the final data display page I can't figure out how to return the full page template. Currently the final data display is also showing within an AJAX pop-up.
 
I've tried adding data-redirect="on" but it still shows the returned template inside an AJAX pop-up. Is it correct that that data-redirect should redirect away from the original form and display on a new, full page?

Code:
<xf:form action="{{ link('myaddon/mydata') }}" class="block" ajax="true" data-redirect="off">
 
Reading up more here, it appears these messages and my data template view are being displayed inside overlays.

After checking out the XF code, I think the only way to get my data template to display on a full normal page and not an overlay is to redirect to another URL first.

Code:
return $this->redirect($this->buildLink('myaddon/display', $params), '');

So I've made a new display function to do that but I can't figure out how to pass my data params across. Do I need to do something with
ParameterBag, is that used for these cases?

I have the display function as below but doing a var_dump inside it seems the params are empty and not passing anyway. I wonder if I'm even on the right track with this at least? :unsure:

Code:
public function actionDisplay(ParameterBag $params)
...
 
As another solution, is it possible to use return $this->message or return $this->error and have the messages appear in a popup/overlay without specifying ajax="true" on the form?
 
You generally want to redirect after submitting a form to prevent resubmissions.

So I've made a new display function to do that but I can't figure out how to pass my data params across. Do I need to do something with
ParameterBag, is that used for these cases?
Assuming passing the values via the URL is okay, you could capture the input and forward it to the redirected page using query params. The third argument to buildLink will take an array of query params. The ParameterBag object is only for route format params.

This kind of defeats preventing resubmissions I suppose, since the POST request effectively becomes a GET request. Otherwise you'd need to persist the data somewhere like the database or session.
 
Last edited:
Back
Top Bottom