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

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

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

Post by orynider »

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
Former Team Member
Posts: 22011
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

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

Post by RMcGirr83 »

You need to state what it is you are trying to achieve instead of having people guess.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
orynider
Translator
Posts: 270
Joined: Wed Nov 16, 2005 12:48 pm
Location: Arad, România
Name: Florin-Ciprian Bodin
Contact:

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

Post by orynider »

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
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

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

Post by david63 »

$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!

I now no longer support any of my extensions but they will start to become available here
User avatar
martti
Registered User
Posts: 911
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

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

Post by martti »

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”