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

Redirect:SUCCESS

Discussion in 'XenForo Development Discussions' started by Lu Jia, Oct 6, 2012.

  1. Lu Jia

    Lu Jia Active Member

    PHP:
                    return $this->responseRedirect(
                                    
    XenForo_ControllerResponse_Redirect::SUCCESS,
                                    
    $this->getDynamicRedirect(),
                                    new 
    XenForo_Phrase('your_message_has_been_sent')
                                );
    I have an addon with a form. I want to spam out the message above the forum (like in admin area All templates saved successfully).
    With this code above nothing will appear.
    Thanks for your help and I hope you'll understand my issue :D
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    Make sure your template which triggers the action where this response runs looks something like this:

    Code:
    <xen:form class="AutoValidator"
    
    method="post"​
    action="{xen:adminlink 'form/save', $form}"​
    data-redirect="on">​
    I think the "data-redirect" being set to "on" and the "AutoValidator" class is necessary.

    EDIT: Actually, the data-redirect can be set to on or off... If it's set to "off" the page will not refresh after the data is saved, but the message should appear. On, would make the page refresh.

    EDIT 2: Also, I never tend to use getDynamicRedirect...

    Here's similar code from a recent add-on of mine:

    PHP:
    return $this->responseRedirect(
        
    XenForo_ControllerResponse_Redirect::SUCCESS,
        
    XenForo_Link::buildAdminLink('add-ons/build') . $this->getLastHash($addOnId),
        new 
    XenForo_Phrase('your_addon_has_been_built')
    );                     
    Notice, I refer back to a URL...
     
    rour and Lu Jia like this.
  3. Lu Jia

    Lu Jia Active Member

    It still doesn't work :(
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Weird.

    And getDynamicRedirect works so that should be fine...
     
  5. Lu Jia

    Lu Jia Active Member

    I found the error in my form tag I got 2 class like:
    HTML:
    <form class="xenForm" class="AutoValidator">
    That's why it doesn't work just merge them:
    HTML:
    <form class="xenForm AutoValidator">
    It works now! Thanks for your help man :)
     
    Chris D likes this.
  6. Chris D

    Chris D XenForo Developer Staff Member

    Ahh, yeah that will do it.

    Nice one :)
     
  7. Lu Jia

    Lu Jia Active Member

    New issue :)
    I know the second argument will pass the redirectlink
    PHP:
        public $redirectTarget '';
    but it seems doesn't work.
    This is my code:
    PHP:
                    $redirectUrl 'scanteam/'.$scanteam_alias.'.'.$scanteam_id.'/admin';
                   
                    return 
    $this->responseRedirect(
                                    
    XenForo_ControllerResponse_Redirect::RESOURCE_CREATED,
                                    
    $redirectUrl,
                                    new 
    XenForo_Phrase('your_scanteam_has_been_create')
                                );       
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    Use:

    XenForo_Link::buildPublicLink($redirectUrl)

    So...

    PHP:
    $redirectUrl 'scanteam/'.$scanteam_alias.'.'.$scanteam_id.'/admin';

    return 
    $this->responseRedirect(
        
    XenForo_ControllerResponse_Redirect::RESOURCE_CREATED,
        
    XenForo_Link::buildPublicLink($redirectUrl),
        new 
    XenForo_Phrase('your_scanteam_has_been_create')
    );
    Technically what you've already got should work, but you should always use XenForo_Link or {xen:link as it builds the URL properly and stays consistent with the type of URLs used on the board. So technically what you've done above will only work on boards with full friendly URLs configured.
     
  9. Lu Jia

    Lu Jia Active Member

    Oh, my is a specific addon, I guess no one will need it :D
    It still doesn't work. All works fine (query and other stuff) just redirect doesn't work.
    Any suggestion?
     
  10. account8226

    account8226 Guest

    Is there a way to pass out vars on this reponseRedirect method ? I would like to show to my user the content he just submitted.
     
  11. Chris D

    Chris D XenForo Developer Staff Member

    PHP:
    $redirectUrl XenForo_Link::buildPublicLink('index');
     
    $params = array(
        
    'animal' => 'cat',
        
    'name' => 'Garfield'
    );

    return 
    $this->responseRedirect(
        
    XenForo_ControllerResponse_Redirect::RESOURCE_CREATED,
        
    $redirectUrl,
        new 
    XenForo_Phrase('thank_you_for_submitting_your_x_named_y_to_our_database'$params)
    );
    You would then set your phrase up as:

    Title: thank_you_for_submitting_your_x_named_y_to_our_database

    Phrase: Thank you for submitting your {animal} named {name} to our database

    This would then result in your redirect message saying:

    "Thank you for submitting your cat named Garfield to our database"
     
    KiF and (deleted member) like this.
  12. account8226

    account8226 Guest

    Amazing thanks you so much Chris <3 I was correctly using the method, but I didn't know how to do for params, thanks :) :) (y)
     
    Chris D likes this.
  13. account8226

    account8226 Guest

    I read to quickly,

    In fact I would like to do the same, but on my redirected page (not in the top message). Would adding the $params array as a second parameter of the buildPublicLink method work ?

    In fact, when submitting my forum, I would like everything to be displayed on a new page.
     

Share This Page