1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'XenForo Development Discussions' started by Chris D, Aug 24, 2012.

  1. Chris D

    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?
  2. Chris D

    Chris D XenForo Developer Staff Member

    Ok, I have this and it's working:

    return $this->responseRedirect(
    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:
    Elly likes this.
  3. Digital Doctor

    Digital Doctor Well-Known Member

    I guess you could save all the variables, let it refresh, and then re-populate the page with the latest save ?
    Chris D likes this.
  4. ragtek

    ragtek Guest

    try to add

    to your form

    <form action="{xen:link 'foo'}" method="post" class="xenForm"
    Mr. Goodie2Shoes and Chris D like this.
  5. Robbo

    Robbo Well-Known Member

    In your form element add class="AutoValidator", will probably need what ragtek said as well.
    Mr. Goodie2Shoes and Chris D like this.
  6. Chris D

    Chris D XenForo Developer Staff Member

    Yep, I had data-redirect="on"


    Thank you both.
  7. Marcus

    Marcus Well-Known Member

    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.
  8. digitalpoint

    digitalpoint Well-Known Member

    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:

    XenForo.alert('Something you want to say...', '', 4000);
    (4000 is the milliseconds for it to display)
    Sidane, Marcus and Chris D like this.
  9. Marcus

    Marcus Well-Known Member

    Thanks, that looks great.

    It's so much fun to learn more about xenforos internals, I made my forum_list 35% faster today, yay!
  10. melbo

    melbo Well-Known Member

    Care to share your tips :)
  11. Marcus

    Marcus Well-Known Member

    With data-redirect="on" I can use the redirect in php. It didn't work otherwise. That works now:
     return $this->responseRedirect(
  12. account8226

    account8226 Guest

    And have you found a way to store the vars and parse them into a new page, after redirection ?
  13. Chris D

    Chris D XenForo Developer Staff Member

    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.
  14. account8226

    account8226 Guest

    I was asking the same question as the other thread ;) Thanks.
    Chris D likes this.

Share This Page