$_POST array

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

$_POST array

Post by eeji »

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.
My phpBB styles: phpbbstyles.iansvivarium.com
My "board": iansvivarium.com
(yes, it's running phpBB!)
rxu
Extensions Development Team
Posts: 3711
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Contact:

Re: $_POST array

Post by rxu »

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
Registered User
Posts: 1461
Joined: Fri Dec 12, 2008 9:08 pm
Location: Manchester, UK
Contact:

Re: $_POST array

Post by eeji »

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
My phpBB styles: phpbbstyles.iansvivarium.com
My "board": iansvivarium.com
(yes, it's running phpBB!)
rxu
Extensions Development Team
Posts: 3711
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Contact:

Re: $_POST array

Post by rxu »

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: 131
Joined: Sat Nov 24, 2018 7:48 pm

Re: $_POST array

Post by Nick225 »

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: 213
Joined: Mon Feb 26, 2018 9:32 pm
Name: B!

Re: $_POST array

Post by caiocald »

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: 131
Joined: Sat Nov 24, 2018 7:48 pm

Re: $_POST array

Post by Nick225 »

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: 213
Joined: Mon Feb 26, 2018 9:32 pm
Name: B!

Re: $_POST array

Post by caiocald »

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

Re: $_POST array

Post by mrgoldy »

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

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
Post Reply

Return to “Extension Writers Discussion”