Request var in listener?

Discussion forum for Extension Writers regarding Extension Development.
User avatar
martti
Registered User
Posts: 671
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: Request var in listener?

Post by martti » Sat Jun 09, 2018 6:38 pm

Toxyy wrote:
Sat Jun 09, 2018 4:05 pm
I understand that but request_var is getting variables from the wrong url (unless I do vardump), I need to use request_var on the original posting.php link that I made in viewtopic somehow...
I don't see the whole context. Just a guess:
Are you submitting a form? Is your parameter set in the action atrribute? (or in the post body as a hidden field? - in case of a post-form)
Otherwise: Open the "network inspector" of your browser to see if a redirect happens.

User avatar
Toxyy
Registered User
Posts: 542
Joined: Mon Oct 24, 2016 3:22 pm
Contact:

Re: Request var in listener?

Post by Toxyy » Sat Jun 09, 2018 6:43 pm

martti wrote:
Sat Jun 09, 2018 6:38 pm
Toxyy wrote:
Sat Jun 09, 2018 4:05 pm
I understand that but request_var is getting variables from the wrong url (unless I do vardump), I need to use request_var on the original posting.php link that I made in viewtopic somehow...
I don't see the whole context. Just a guess:
Are you submitting a form? Is your parameter set in the action atrribute? (or in the post body as a hidden field? - in case of a post-form)
Otherwise: Open the "network inspector" of your browser to see if a redirect happens.
I'm making a separate "post comment" button per post, so I'm adding c=1 to the url in viewtopic.php and I want to reflect that in posting.php.

So yes I am submitting a form on the posting.php page. Network inspector shows it goes to a second posting.php, which is $s_action, and the events are being processed there. The show events extension shows that they are processed at least once on the first page..

@3Di, I'll get on that later tonight, thank you
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

My extensions:
[3.2][BETA] Anonymous Posts || [3.2][RC] Show User Activity

User avatar
Toxyy
Registered User
Posts: 542
Joined: Mon Oct 24, 2016 3:22 pm
Contact:

Re: Request var in listener?

Post by Toxyy » Mon Jun 11, 2018 1:02 am

After a lot of testing and googling, I've finally come up with this:

Code: Select all

        public function posting_modify_template_vars(event $event)
        {
                $data = $event->get_data();
                
                $data['page_data']['S_POST_ACTION'] .= '&c=' . $this->request->variable('c', '') . '&';
                
                $event->set_data($data);
        }
        
        public function submit_post_modify_sql_data($event)
        {
                $sql_data = $event['sql_data'];
                
                $comment_mode = $this->request->variable('c', '');
                
		$sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array(
                        'parent_id' => $comment_mode == 1 ? $event['data']['parent_id'] : 0,
                ));
                
		$event['sql_data'] = $sql_data;
        }
And it works great. I tried appending to $event['s_action'], but functions use $event['page_data']['S_POST_ACTION'] instead. Appending to $event['page_data']['S_POST_ACTION'] itself didn't seem to work either.

Thanks for the help everyone! Hopefully this solution won't be denied :)

3Di I'll make a github when I have something to show for all of this work, haha
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

My extensions:
[3.2][BETA] Anonymous Posts || [3.2][RC] Show User Activity

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 12 guests