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

How to direct to a new page on form submission?

Discussion in 'XenForo Development Discussions' started by Tristan10, Jul 29, 2016.

  1. Tristan10

    Tristan10 Member

    I have followed this tutorial to make a simple add on and adapt it to my own needs.

    Basically the user goes to the page and submits a value in a form. After submitting, the page just refreshes as of right now. I would like to direct them to a new page with another form that they can submit. How do I accomplish this? Do I need a new template or page? How do I add another route prefix to handle it (if I need it)? Any help is appreciated.
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    Your current code, based on that review, has this in its controller:
    PHP:
    //Send a response to the user, so he know that everything went fine with this action
    return $this->responseRedirect(
        
    XenForo_ControllerResponse_Redirect::SUCCESS,
        
    $this->getDynamicRedirect()
    );
    It's the getDynamicRedirect() line that redirects you to the same page.

    You can specify any link you like here. Use XenForo's link builder:

    PHP:
    //Send a response to the user, so he know that everything went fine with this action
    return $this->responseRedirect(
        
    XenForo_ControllerResponse_Redirect::SUCCESS,
        
    XenForo_Link::buildPublicLink('route/action'$linkData, array('query' => 'string'));
    );
    The second and third parameters there are optional.

    Look through exising XenForo code for where "buildPublicLink" is used to get an idea of how it works.
     
  3. Tristan10

    Tristan10 Member

    I don't really understand. Sorry, I am REALLY new at this. I have created another page that I want to redirect them to. But I don't know how to use buildPublicLink or Routes/Prefixes. Let alone together. Could you elaborate a little more? Or tell me where I can find information regarding these things? Thanks.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    What's the URL of the page you would like to redirect to?
     
  5. Tristan10

    Tristan10 Member

  6. Chris D

    Chris D XenForo Developer Staff Member

    One way to build that link is like this:
    PHP:
    //Send a response to the user, so he know that everything went fine with this action
    return $this->responseRedirect(
        
    XenForo_ControllerResponse_Redirect::SUCCESS,
        
    XenForo_Link::buildPublicLink('pages', array('node_name' => 'XboxVerificationConfirm'));
    );
     
    Tristan10 likes this.

Share This Page