Response that doesn't redirect but instead displays custom "your changes have been saved" message

Chris D

XenForo developer
Staff member
I'm looking for a way so that after a user clicks a submit button in my add on and the relevant actions have happened that instead of being redirected to another page, they stay on the same page - without it bring refreshed at all and confirmation that the action has been completed will display in the header.

Big thing Is - is this even possible without refreshing the page?
 
Ok, I have this and it's working:

Rich (BB code):
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,​
XenForo_Link::buildPublicLink('route/action'),​
new XenForo_Phrase('my_success_phrase')​
);

But what happens, of course, is the page is refreshed so any data filled in on the form elements are removed. Ideally, I don't want a redirect to happen. I just want the data from the form to be process, and my_success_phrase displayed at the top.

Or, some other way of keeping the data on screen after a refresh (the data isn't stored in the database). Maybe I could cookie it... But ideally I just don't want a redirect to happen. Hopefully there's a solution. I'm hoping I'm just missing something :unsure:
 
Is it possible to trigger a "your changes have been saved" message without using a form? I use a link for deleting items. After clicking on the link, the item is deleted. Then the message should appear.
 
Is it possible to trigger a "your changes have been saved" message without using a form? I use a link for deleting items. After clicking on the link, the item is deleted. Then the message should appear.
If the link is an AJAX request I think you can add a "message" parameter to the returned JSON and it will display that message.

If you want to do it with your own JavaScript, you can do this:

Code:
XenForo.alert('Something you want to say...', '', 4000);
(4000 is the milliseconds for it to display)
 
Thanks, that looks great.

It's so much fun to learn more about xenforos internals, I made my forum_list 35% faster today, yay!
 
Yep, I had data-redirect="on"
With data-redirect="on" I can use the redirect in php. It didn't work otherwise. That works now:
PHP:
 return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
  XenForo_Link::buildPublicLink('a', $a),
new XenForo_Phrase('your_message_has_been_posted')
  );
 
There's many ways.

You would usually store them in the database.

Alternatively you could store them temporarily in a cookie, or PHP session, or simple cache... lots of ways really.
 
There's many ways.

You would usually store them in the database.

Alternatively you could store them temporarily in a cookie, or PHP session, or simple cache... lots of ways really.

I was asking the same question as the other thread ;) Thanks.
 
Top Bottom