Troubles with form and request class

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Varadia
Registered User
Posts: 2
Joined: Sun Aug 01, 2021 1:43 am

Troubles with form and request class

Post by Varadia »

Hello,

As the title say, I'm having trouble understanding and using forms and specifically on the request part.
Here is my form:

Code: Select all

<form method="post" action="hidden_ok">
	<select name="forum_id">
	<!-- BEGIN forumrow -->
		
		<option value='{forumrow.FORUM_ID}'>{forumrow.FORUM_NAME}</option>
			
	<!-- END forumrow -->
	</select>
	
	<INPUT TYPE=SUBMIT VALUE="Créer">
	
</form>
And here are the tests I made on it:

Code: Select all

$request = new \phpbb\request\request();
if(isset($request) && !empty($request)) {
	if($request->is_set_post('forum_id'))
	{
		echo $request->variable('forum_id','defaut').'<br>';
		echo $request->get_super_global().'<br>';
		echo $request->variable_names();
	}
	
}
return $this->helper->render('@poudlard1900_hidden/hidden_ok.html');
I get this on my page:

defaut
2
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/request/request.php on line 386: array_keys() expects parameter 1 to be array, int given

Meaning, if I understand correctly, that the forum_id value is not defined, but I don't understand why since the request is set. I don't get either why the get_super_global tell me "2", or why do I have an error on variable names. What am I missing?
User avatar
AlfredoRamos
Recognised Extension Developer
Posts: 1302
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo
Contact:

Re: Troubles with form and request class

Post by AlfredoRamos »

Varadia wrote: Wed Aug 04, 2021 7:11 pm Meaning, if I understand correctly, that the forum_id value is not defined, but I don't understand why since the request is set
It has nothing to do with the request instance.

You are getting the default value you've specified (default) because it couldn't find that field when that snippet was executed.
Varadia wrote: Wed Aug 04, 2021 7:11 pm I don't get either why the get_super_global tell me "2"
Because that's the value of the REQUEST constant, which is the default interface used when you don't specify one.

- https://github.com/phpbb/phpbb/blob/f83 ... ce.php#L26
- https://github.com/phpbb/phpbb/blob/f83 ... t.php#L427
Varadia wrote: Wed Aug 04, 2021 7:11 pm why do I have an error on variable names.
I'm not sure about that one, it could be a bug, or the way it's being used.
Varadia wrote: Wed Aug 04, 2021 7:11 pm What am I missing?
It's hard to help you without knowing what are you doing, because it doesn't look like you are using controllers or dependency injection.

- https://area51.phpbb.com/docs/dev/3.3.x ... cepts.html
- https://area51.phpbb.com/docs/dev/3.3.x ... llers.html
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
Varadia
Registered User
Posts: 2
Joined: Sun Aug 01, 2021 1:43 am

Re: Troubles with form and request class

Post by Varadia »

I was using controllers but overlooked dependency injection. All is well now, thanks a lot for your fast answer!
Post Reply

Return to “Extension Writers Discussion”