Redirect within an Event used by an extension

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

Redirect within an Event used by an extension

Post by EVO_VV »

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
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Redirect within an Event used by an extension

Post by mrgoldy »

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.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
EVO_VV
Registered User
Posts: 55
Joined: Tue Feb 13, 2018 3:11 pm

Re: Redirect within an Event used by an extension

Post by EVO_VV »

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”