• 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?

#1
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.
 

Chris D

XenForo developer
Staff member
#2
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
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.
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.
 

Chris D

XenForo developer
Staff member
#6
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'));
);