Your status has been updated - drop down code

AndyB

Well-known member
I would like to have a drop down similar to the "Your status has been updated" notice.

pic001.webp

In my add-on "Flag Thread" I confirm an action by using the following code:

PHP:
return $this->responseMessage('Thread successfully flagged');

You can see the entire PHP code here:

http://xenforo.com/community/threads/flag-thread-v1-0.64451/#post-680040

Using the return $this->responseMessage() sends the user to another page to make the confirmation. It would be great to be able to stay on the current thread and have a notice like "Your status has been updated" drop down with a different message.
 
Add class AutoValidator to your form and use responseRedirect

PHP:
$thread = $threadModel->getThreadById($threadId);

return $this->responseRedirect(
    XenForo_ControllerResponse_Redirect::SUCCESS,
    XenForo_Link::buildPublicLink('threads', $thread),
    'Thread successfully flagged'
);
 
Can you add class="TriggerOverlay" (I think that's the class name, can't check right now)?

May I ask why you chose to make a new route for this? Seems as if you could have just extended the thread controller to have actionFlag().

You should also use the {xen:link} functionality instead of the URL method you're using (in my opinion).
 
Can you add class="TriggerOverlay" (I think that's the class name, can't check right now)?

Thank you, Daniel.

Adding class="OverlayTrigger" did the trick! Now I get the Overlay drop down.

Code:
$0
<xen:if is="{$visitor.is_admin}">
<li><a href="{$requestPaths.fullBasePath}flagthread?flag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" />{xen:phrase flag_thread}</a></li>
<li><a href="{$requestPaths.fullBasePath}flagthread?unflag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" />{xen:phrase unflag_thread}</a></li>
</xen:if>
 
Last edited:
Is it possible to have the page reload after the OverlayTrigger drop down? It would be nice to have the Overlay confirm the action and then immediately after the message the page would reload.
 
Last edited:
add data-redirect="on" to your form

Hi xf_phantom,

I tried that, but unfortunately doesn't force a page reload.

Code:
$0
<xen:if is="{$visitor.is_admin}">
<li><a href="{$requestPaths.fullBasePath}flagthread?flag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" data-redirect="on" />{xen:phrase flag_thread}</a></li>
<li><a href="{$requestPaths.fullBasePath}flagthread?unflag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" data-redirect="on" />{xen:phrase unflag_thread}</a></li>
</xen:if>
 
I'm not using a form, I'm using <a href> link.

I added Flag Thread and Unflag Thread links as shown here:

pic001.webp

The Template Modification code I currently have is:

Code:
$0
<xen:if is="{$visitor.is_admin}">
<li><a href="{$requestPaths.fullBasePath}flagthread?flag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" />{xen:phrase flag_thread}</a></li>
<li><a href="{$requestPaths.fullBasePath}flagthread?unflag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" />{xen:phrase unflag_thread}</a></li>
</xen:if>
 
Thank you, Milano, Daniel Hood and xf_phantom.

With the help from all three of you I have coded my add-on the proper way. Clicking the Flag Thread or Unflag Thread link now brings up an overlay form and once the admin clicks Submit, the code runs an action.

I also removed the unnecessary Route Prefix.
 
Last edited:
Top Bottom