How to Capturing the topic_id variable inside a form action (controller with route)? [resolved]

Discussion forum for Extension Writers regarding Extension Development.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Help with the adaptation of a tool in php for phpbb extension

Post by mrgoldy »

Stop quoting me. Now you're just straight up being needy. Quoting me in every reply.. I am not your personal troubleshooter.

And the answer to your issue has already been posted..
the $request and <input> names have to be the same.
Your request name: t
Your input name: topic_id
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
caiocald
Registered User
Posts: 213
Joined: Mon Feb 26, 2018 9:32 pm
Name: B!

Re: Help with the adaptation of a tool in php for phpbb extension

Post by caiocald »

Sorry, you did not solve my problem with this code. And I'm not lacking, I'm just trying to learn phpbb. by the way, neither you nor I are born knowing anything.

My extension form appears on more than one topic.

When the user clicks submit on the form, the form will need to submit the topic_id in which the form was located.

So I tried using echo = $ _get ['f'] on imput hidden. But it did not work (Then I went to find out that phpbb had suppressed this variable for security reasons).

My extension it will function as a scoring tool and appears on the viewtopic page via a hook event (viewtopic_panel_post_body_inner.html).

So if anyone is reading this topic: no, my problem has not been fixed.
I still need help, so feel free to help me.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: How to Capturing the topic_id variable inside a form action (controller with route)?

Post by mrgoldy »

Lets bite the hand that feeds you.
Just quoting me to make sure I get a notification, is what I call needy, that's why I asked you to stop quoting me.
And I know people are not born all-knowing, that's why I am trying to help you, but you will not take it.

So, I am going to try this one last time to make it clear:
You have a <form> located here: viewtopic_panel_post_body_inner.html#L22-L61
And you have a controller that should handle the submission of that form: controller.

Your <form action="pontuacao"> is a hard coded string, you will have to change this to: {{ path('red1000_pontuacao_formulariopontuacao') }}.
Then you have two hidden input fields.
Hidden iput 1: id
Hidden input 2: topic_id
Both have NO value assign, see the vale="", so even if you request them, you will get no value from them.
Seeing that template event is within the viewtopic.php, you can simply use {{ TOPIC_ID }} to get the id of the current topic.
So that would make it:
<input type="hidden" name="topic_id" value="{{ TOPIC_ID }}">

Then in your controller, you try to request a variable here.
The name="" of the variable you are trying to request, is t. As you can see, neither of your hidden input fields have the name="t".
So you will have to change that to $topic_id = $this->request->variable('topic_id', 0);, as <input name="topic_id"> does exist, and now also has the value of the actual topic id.

Alternatively, you can also define those parameters in your action url, so that would look like this:
<form action="{{ path('red1000_pontuacao_formulariopontuacao', {'some_variable': 16}) }}" ..
$some_variable = $this->request->variable('some_variable', 0); // Result: 16
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
caiocald
Registered User
Posts: 213
Joined: Mon Feb 26, 2018 9:32 pm
Name: B!

Re: How to Capturing the topic_id variable inside a form action (controller with route)?

Post by caiocald »

mrgoldy wrote: Sat Dec 22, 2018 11:43 am Lets bite the hand that feeds you.
Just quoting me to make sure I get a notification, is what I call needy, that's why I asked you to stop quoting me.
And I know people are not born all-knowing, that's why I am trying to help you, but you will not take it.

So, I am going to try this one last time to make it clear:
You have a <form> located here: viewtopic_panel_post_body_inner.html#L22-L61
And you have a controller that should handle the submission of that form: controller.

Your <form action="pontuacao"> is a hard coded string, you will have to change this to: {{ path('red1000_pontuacao_formulariopontuacao') }}.
Then you have two hidden input fields.
Hidden iput 1: id
Hidden input 2: topic_id
Both have NO value assign, see the vale="", so even if you request them, you will get no value from them.
Seeing that template event is within the viewtopic.php, you can simply use {{ TOPIC_ID }} to get the id of the current topic.
So that would make it:
<input type="hidden" name="topic_id" value="{{ TOPIC_ID }}">

Then in your controller, you try to request a variable here.
The name="" of the variable you are trying to request, is t. As you can see, neither of your hidden input fields have the name="t".
So you will have to change that to $topic_id = $this->request->variable('topic_id', 0);, as <input name="topic_id"> does exist, and now also has the value of the actual topic id.

Alternatively, you can also define those parameters in your action url, so that would look like this:
<form action="{{ path('red1000_pontuacao_formulariopontuacao', {'some_variable': 16}) }}" ..
$some_variable = $this->request->variable('some_variable', 0); // Result: 16
I do not even know where to start.

I just wanted to say that I'm crying a lot. I spent more than a year designing and trying to reconcile phpbb studies with my college.
Thanks to you, I have finally achieved a dream and I can finally help my users with this extension I designed to help with their writing studies.

mrgoldy, I would really like to thank you. You made my dream come true.

I will update the topic title to resolved.

THANK YOU.
User avatar
caiocald
Registered User
Posts: 213
Joined: Mon Feb 26, 2018 9:32 pm
Name: B!

Re: How to Capturing the topic_id variable inside a form action (controller with route)?

Post by caiocald »

Could you clarify one last doubt?

I uploaded my extension to my server and it is returning this error:
SQL ERROR [ mysqli ]

Table 'phpb884.PHPBBKK_PONTUACAO_ENEM' doesn't exist [1146]

Code: Select all

SQL
SQL ERROR [ mysqli ]
Table '.PHPBB_PONTUACAO_ENEM' doesn't exist [1146]
SQL
SELECT COUNT(*) AS number_of_rows , avg(comp1) as comp1 , avg(comp2) as comp2 , avg(comp3) as comp3 , avg(comp4) as comp4 , avg(comp5) as comp5 FROM PHPBB_PONTUACAO_ENEM WHERE topic_id = 5476
BACKTRACE
Using xampp (localhost) the extension works perfectly. But does my server return this error?

Is DB incompatibility? Can I solve this?

I do not know if it helps, but the prefix of my table in the DB connection is written like this:

Code: Select all

	$sql = 'SELECT *
                FROM ' . 'PHPBBKK_PONTUACAO_ENEM' . '
                WHERE user_id = ' . $this->user->data['user_id'] . '
                AND topic_id = ' . (int) $topic_id;
Once again, thank you!!!
Last edited by caiocald on Sat Dec 22, 2018 2:51 pm, edited 2 times in total.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: How to Capturing the topic_id variable inside a form action (controller with route)?

Post by david63 »

The obvious question would be - does that table exist? Did you create it with your migration file?
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: How to Capturing the topic_id variable inside a form action (controller with route)?

Post by mrgoldy »

Look at the Skeleton extension.
You have to add a table through migrations.
Then declare that table in your parameters.yml and import that into your services.yml.
Then in the file you need it, for instance your controller, inject it as a dependency.

phpBB's Board Rules example:
- Migrations
- Tables.yml
- import in services
- inject as a service
- construct it
- use it
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
caiocald
Registered User
Posts: 213
Joined: Mon Feb 26, 2018 9:32 pm
Name: B!

Re: How to Capturing the topic_id variable inside a form action (controller with route)?

Post by caiocald »

mrgoldy wrote: Sat Dec 22, 2018 2:12 pm Look at the Skeleton extension.
You have to add a table through migrations.
Then declare that table in your parameters.yml and import that into your services.yml.
Then in the file you need it, for instance your controller, inject it as a dependency.

phpBB's Board Rules example:
- Migrations
- Tables.yml
- import in services
- inject as a service
- construct it
- use it

Worked perfectly!

Your messages should be attached in the phpbb extension tutorial!

I did not know that the tables.yml file existed

Extension COMPLETED!
https://projetoredacaonota1000.com.br/v ... f=5&t=5477
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: How to Capturing the topic_id variable inside a form action (controller with route)? [resolved]

Post by mrgoldy »

For the love of ...
Please stop quoting for no other purpose than to give me a notification............!!!!!!!!!
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
caiocald
Registered User
Posts: 213
Joined: Mon Feb 26, 2018 9:32 pm
Name: B!

Re: How to Capturing the topic_id variable inside a form action (controller with route)? [resolved]

Post by caiocald »

<3
Post Reply

Return to “Extension Writers Discussion”