Redirect within an Event used by an extension

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
EVO_VV
Registered User
Posts: 46
Joined: Tue Feb 13, 2018 3:11 pm

Redirect within an Event used by an extension

Post by EVO_VV » Thu Apr 12, 2018 4:32 am

I'm currently using posting.php's core.modify_posting_parameters Event to trigger operations upon the click of an inserted button.
At the moment I am setting $event['cancel'] to True so that when the return from the event occurs posting.php executes the if ($cancel) code which then performs a redirect, which is what I want to occur.

Is there any reason that it would not be safe to perform that redirect within the extension's code instead of returning to posting.php ?

User avatar
posey
Registered User
Posts: 706
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Redirect within an Event used by an extension

Post by posey » Fri Apr 13, 2018 7:25 am

Really hard to judge without code and thoughts behind the code.
But it sounds like, when you set the cancel to true, the initial action will not go through at all.
Might be better to set an additional parameter and check for that parameter after submit and redirect to the appropiate url.
''I'm pretty sure there's a lot more to life than being really, really, ridiculously good looking. And I plan on finding out what that is.''

EVO_VV
Registered User
Posts: 46
Joined: Tue Feb 13, 2018 3:11 pm

Re: Redirect within an Event used by an extension

Post by EVO_VV » Fri Apr 13, 2018 10:29 am

Thanks Posey, sorry I did not explain it too well.
Here is the code in the listener.php with the unnecessary stuff omitted :-

Code: Select all

	public function button_action($event)
	{
		// 'button_reason' is set by clicking the button which then triggers the event
		$button_reason = $this->request->variable('button_reason', '', true);

		if ($button_reason != "This")
		{
			// It was not my inserted button that was clicked so get out
			return;  
		}

		$post_id = $event['post_id'];
		$forum_id = $event['forum_id'];
		
		// This is where the relevant code is to perform the required actions when my button is clicked

		// This is the current code to control the subsequent redirect on return to posting.php
		$event['topic_id'] = $topic_id;
		$event['post_id'] = $next_post_id;
		$event['cancel'] = true;

	}
Can I replace those last three lines with the redirect I want and not return at all to posting.php or will that cause problms ?

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 12 guests