Redirect:SUCCESS

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
 
Make sure your template which triggers the action where this response runs looks something like this:

Rich (BB 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...
 
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 :)
 
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 :)
Ahh, yeah that will do it.

Nice one :)
 
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')
                            );
 
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.
 
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?
 
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.

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.
 
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"
 
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"

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)
 
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"

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.
 
Back
Top Bottom