$_POST array

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
eeji
Jr. Style Validator
Posts: 1074
Joined: Fri Dec 12, 2008 9:08 pm
Location: Manchester, UK
Contact:

$_POST array

Post by eeji » Sat Sep 26, 2015 6:44 pm

how can I access the $_POST array only (ignoring any $_GET values and anything else that gets added) via the request class?
I'm upgrading my site from 3.0 to 3.1 and I need to unset one value then run the array through a foreach loop.
Free styles: phpbbstyles.oo.gd
My board: iansvivarium.com

rxu
Extensions Development Team
Posts: 2945
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: $_POST array

Post by rxu » Sun Sep 27, 2015 2:33 am

The request class uses $_REQUEST by default to get values, so you need to set $_POST if you need, like

Code: Select all

$myvar = $request->variable('myvar', true, \phpbb\request\request_interface::POST);
The secong parameter (boolean) indicates whether the variable should contain multibyte (UTF8) characters.

User avatar
eeji
Jr. Style Validator
Posts: 1074
Joined: Fri Dec 12, 2008 9:08 pm
Location: Manchester, UK
Contact:

Re: $_POST array

Post by eeji » Sun Sep 27, 2015 7:36 pm

can I get the whole $_POST array? I'm sorry for the noob questions, I'm really clueless when it comes to OOP so the latest phpbb has thrown me a massive curve ball :D
Free styles: phpbbstyles.oo.gd
My board: iansvivarium.com

rxu
Extensions Development Team
Posts: 2945
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: $_POST array

Post by rxu » Mon Sep 28, 2015 1:52 pm

eeji wrote:can I get the whole $_POST array?
You can do it like that

Code: Select all

$post_vars_array = $request->variable_names(\phpbb\request\request_interface::POST); 
This way you'll get an array with the $_POST variable names which can be used to get their values via $request->variable();.

Nick225
Registered User
Posts: 106
Joined: Sat Nov 24, 2018 7:48 pm

Re: $_POST array

Post by Nick225 » Fri Dec 21, 2018 10:19 pm

rxu wrote:
Mon Sep 28, 2015 1:52 pm
eeji wrote:can I get the whole $_POST array?
You can do it like that

Code: Select all

$post_vars_array = $request->variable_names(\phpbb\request\request_interface::POST); 
This way you'll get an array with the $_POST variable names which can be used to get their values via $request->variable();.
So if you are posting 12 different fields with various types, you have to request_var for each of them?
$post_vars_array = $request->variable_names(\phpbb\request\request_interface::POST);
string1 = request_var('string1 ', '', true);
string2 = request_var('string2 ', '', true);
int1 = request_var('int1', 0);
string3 = request_var('string3 ', '', true);
...
...
or list all the types in an array and loop through to get all of them?

Hope I am totally wrong.. because that would be too complicated. There got to be a better way.

User avatar
caiocald
Registered User
Posts: 60
Joined: Mon Feb 26, 2018 9:32 pm
Location: Brasil
Name: B!
Contact:

Re: $_POST array

Post by caiocald » Fri Dec 21, 2018 10:29 pm

In my extension project I used this code to select my requests.
I do not speak English very well, I hope I have helped.

Code: Select all

$data = array(
                    'comp1' => $this->request->variable('comp1',0),
                    'comp2' => $this->request->variable('comp2',0),
                    'comp3' => $this->request->variable('comp3',0),
                    'comp4' => $this->request->variable('comp4',0),
                    'comp5' => $this->request->variable('comp5',0),
                );

Nick225
Registered User
Posts: 106
Joined: Sat Nov 24, 2018 7:48 pm

Re: $_POST array

Post by Nick225 » Fri Dec 21, 2018 11:14 pm

Yup.. That's what I am thinking. Request them one by one and list their types.
The idea of _Post and use your data is now history. You have to tell us what every field is.

User avatar
caiocald
Registered User
Posts: 60
Joined: Mon Feb 26, 2018 9:32 pm
Location: Brasil
Name: B!
Contact:

Re: $_POST array

Post by caiocald » Fri Dec 21, 2018 11:48 pm

Nick225 wrote:
Fri Dec 21, 2018 11:14 pm
Yup.. That's what I am thinking. Request them one by one and list their types.
The idea of _Post and use your data is now history. You have to tell us what every field is.
Yes!

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1051
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: $_POST array

Post by mrgoldy » Sat Dec 22, 2018 11:05 am

Yes, but seeing it is user input, you have to make sure it is within the "allowed" parameters that you expect the user to input. Do error checking on it, etc.
phpBB Studio / ''Proud member of the Studio"

Post Reply

Return to “Extension Writers Discussion”