How to do Request() -> $_POST[][] ??

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
orynider
Registered User
Posts: 135
Joined: Wed Nov 16, 2005 12:48 pm
Location: Arad, România
Name: Florin Bodin
Contact:

How to do Request() -> $_POST[][] ??

Post by orynider » Tue Mar 20, 2018 1:30 pm

Hi,

I did try in phpBB something like this:

Code: Select all

$this->request->variable(['translate']['file'], '');
I'm searching how to get:

Code: Select all

$_POST['translate']['file']
:?

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 20762
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: How to do Request() -> $_POST[][] ??

Post by RMcGirr83 » Tue Mar 20, 2018 2:32 pm

You need to state what it is you are trying to achieve instead of having people guess.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

User avatar
orynider
Registered User
Posts: 135
Joined: Wed Nov 16, 2005 12:48 pm
Location: Arad, România
Name: Florin Bodin
Contact:

Re: How to do Request() -> $_POST[][] ??

Post by orynider » Tue Mar 20, 2018 3:01 pm

It's in the function construct() of the translator class at witch I'm working atm.
I come to something like this:

Code: Select all

$language = $this->request->variable('language', array('into' => 'en'));
print_r($language['into']);
I get:

Code: Select all

es
edit:
This outside phpBB would be:

Code: Select all

$language_into = $_POST['language']['into'];

User avatar
david63
Jr. Extension Validator
Posts: 13896
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: How to do Request() -> $_POST[][] ??

Post by david63 » Tue Mar 20, 2018 3:31 pm

$this->request->is_set_post('some_variable')
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
martti
Registered User
Posts: 446
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: How to do Request() -> $_POST[][] ??

Post by martti » Thu Apr 12, 2018 4:57 am

orynider wrote:
Tue Mar 20, 2018 3:01 pm

Code: Select all

$language = $this->request->variable('language', array('into' => 'en'));
print_r($language['into']);
I get:

Code: Select all

es
With

Code: Select all

$language = $this->request->variable('language', array('into' => 'en'));
If your HTTP request contains language[into]=es, then you'll get

Code: Select all

var_dump($language);

/* result:

array(1) {
  ["into"]=>
  string(2) "es"
}

*/
If in your HTTP request the language parameter was not set, you will get the default value:

Code: Select all

var_dump($language);

/* result:

array(1) {
  ["into"]=>
  string(2) "en"
}

*/
From phpbb\request\request:

Code: Select all

	/**
	* Central type safe input handling function.
	* All variables in GET or POST requests should be retrieved through this function to maximise security.
	*
	* @param	string|array	$var_name	The form variable's name from which data shall be retrieved.
	* 										If the value is an array this may be an array of indizes which will give
	* 										direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a")
	* 										then specifying array("var", 1) as the name will return "a".
	* @param	mixed			$default	A default value that is returned if the variable was not set.
	* 										This function will always return a value of the same type as the default.
	* @param	bool			$multibyte	If $default is a string this paramater has to be true if the variable may contain any UTF-8 characters
	*										Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks
	* @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global
	* 										Specifies which super global should be used
	*
	* @return	mixed	The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
	*					the same as that of $default. If the variable is not set $default is returned.
	*/
	public function variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST)

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests