$this->request->variable return wrong form value

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

$this->request->variable return wrong form value

Post by axe70 »

Code: Select all

$ug = $this->request->variable('w3all_displayonlyfirstpost', ['u_groups']);
do not return the value of the

Code: Select all

<input type="text" name="w3all_displayonlyfirstpost[u_groups]" value="{W3ALL_DISPLAYONLYFIRSTPOST_U_GROUPS}"  />
that's into a form like

Code: Select all

<form id="w3all_displayonlyfirstpost" name="w3all_displayonlyfirstpost" method="post" action="{{ U_ACTION }}">
instead it return ever the value of the last input on the form.
How it is possible? What's wrong?

it seem easier to use

Code: Select all

$this->request->get_super_global(\phpbb\request\request_interface::POST);
Do not take me too serious
Anyway i do not like Discourse
User avatar
AlfredoRamos
Recognised Extension Developer
Posts: 1302
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo
Contact:

Re: $this->request->variable return wrong form value

Post by AlfredoRamos »

axe70 wrote: Mon Sep 19, 2022 8:21 pm What's wrong?
You must specify the default value of u_groups too.

The following example would cast u_groups as string, so you can split a list of comma-separated IDs.

Code: Select all

$u_groups = $this->request->variable('w3all_displayonlyfirstpost', ['u_groups' => '']);
# array(1) { ["u_groups"]=> string(0) "" }
Some of my phpBB extensions:
:chart_with_upwards_trend: SEO Metadata | Image Markdown | :shield: hCaptcha
:trophy: Check out all my validated extensions :trophy:

:penguin: Arch Linux user | Linux Boards :penguin:
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

Re: $this->request->variable return wrong form value

Post by axe70 »

Hi! Thank you Alfredo

testing right now this after this night, when i was sure i had give a try the way you say, but may i confused something into the
http://area51.phpbb.com/docs/dev/master ... quest.html

doing the way you say it return me the entire array of the form and not the specified needed, so i feel uncomfortable with a result like this, where i expect a single var of the array:

Code: Select all

$ug = $this->request->variable('w3all_displayonlyfirstpost', ['u_groups' => '']);
it return:

Code: Select all

Array ( [u_groups] => 1 [forums_ids] => all,87,45 [rep_mode] => 0 [rep_content] => <h3>PREPENDED content You can only view the first post into this topic</h3> ) 


PS and for what it worth to mention this (that's not into documentation):

Code: Select all

 $ug = $this->request->variable('w3all_displayonlyfirstpost', ['' => '']);
return the entire array again, so may i will use this way instead of

Code: Select all

$POST_data = $this->request->get_super_global(\phpbb\request\request_interface::POST);
but Is it consistent or may one day will become not usable?

Is this the way to get an entire array from a form here?
It is ok, since if i try to get a specified one, it fail some way (if i am not wrong in something) :?

[EDITED]
Do not take me too serious
Anyway i do not like Discourse
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28619
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: $this->request->variable return wrong form value

Post by Paul »

Why are you using a array anyway? There are only very specific cases, like checkboxes, where you should use arrays. In other cases you should use in general unique names for your form fields.
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

Re: $this->request->variable return wrong form value

Post by axe70 »

Hello Paul!
Because this way i intended to not rebuild a passed array to be stored into database in an unique row as single value.
In the other way i should rebuild the array, or i'll not be sure that this as index 0 here, is the right one. If some other extension push something into the POST in the middle?

Code: Select all

            [0] => Array
                (
                    [u_groups] => 1,5
                    [forums_ids] => all
                    [rep_mode] => 1
                    [rep_content] => tester
                    [submit] => Submit
                    [creation_time] => 1663752702
                    [form_token] => 3a7095ac7714fb8b0a25fc0014a30a0770926537
                )
[EDITED]
Do not take me too serious
Anyway i do not like Discourse
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28619
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: $this->request->variable return wrong form value

Post by Paul »

Sorry, I don't understand what you are trying to say. Can you post your full code?
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

Re: $this->request->variable return wrong form value

Post by axe70 »

Yes! It is all into extension phpbb-display-only-first-post proposed for validation into extensions db:

Html:
https://github.com/axew3/phpbb-display- ... _body.html

Php:
https://github.com/axew3/phpbb-display- ... roller.php
Do not take me too serious
Anyway i do not like Discourse
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28619
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: $this->request->variable return wrong form value

Post by Paul »

So they are all seperate config items, that you are going to place in in array?

That's really not how you should do it. You should create for each specific configuration item, a new value in the config table (And, if it might contain large text, in the config_text table.), and use seperate fields in your html, with unique names. See for example the boardrules extension: https://github.com/phpbb-extensions/boardrules
Or, use the existing config modules, see for example here; https://github.com/paul999/phpbb_2fa/bl ... module.php
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

Re: $this->request->variable return wrong form value

Post by axe70 »

I always think to the faster solution (referred to my abilities), also in term of execution, so that i do not see the necessity to store into two tables, when i have to query anyway the config_text: i would not want also overload config. Where faster mean +- nothing in this case, but we can argue that it is.
Why should it be stored into different rows/tables overloading things?

Also because 3 to 4 are about values that can be longer than 255 chars, and just one would be ok for the config.
Do not take me too serious
Anyway i do not like Discourse
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28619
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: $this->request->variable return wrong form value

Post by Paul »

They are both already queried, in one single query (and cached if necessary). Storing them separately will not cause any a slower loadtime, but will increase readability and easier to change values but hand if necessary.
User avatar
axe70
Registered User
Posts: 752
Joined: Sun Nov 17, 2002 10:55 am
Location: Italy
Name: Alessio
Contact:

Re: $this->request->variable return wrong form value

Post by axe70 »

Ok Paul. Thank you for all your suggestions and for the fact that your answers let me know each time more.
Thank you again.
Do not take me too serious
Anyway i do not like Discourse
Post Reply

Return to “Extension Writers Discussion”