request_var won't accept unicode (even with multibyte set)

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Someone1234
Registered User
Posts: 4
Joined: Thu Jan 15, 2015 5:09 pm

request_var won't accept unicode (even with multibyte set)

Post by Someone1234 »

I have a form which is receiving this unicode character. As in "Hêllo" (assuming that renders, with the special "e").

When I receive the value using $_POST['Name'] it works, when I receive it using utf8_normalize_nfc(request_var('Name', '', true)) I receive an empty value (nothing at all).

I've tried several variations e.g. request_var('Name', '', false), with or without the utf8_normalize_nfc() but nothing so far as worked. request_var() simply returns an empty string every single time.

I've checked the Wiki article and searched, both just suggest repeatedly setting the 'true' in multibyte and it should work, but it is not.

Any suggestions are helpful. If you try the code below and it works for you please let me know, as it doesn't for me and that might indicate a problem with the PHPBB installation itself.

Board version: 3.1.2
PHP Version: 5.6.0
mbstring Multibyte Support: Enabled
mbstring Multibyte string engine: libmbfl
mbstring HTTP input encoding translation: disabled
libmbfl version: 1.3.2

Full code:

Code: Select all

<!DOCTYPE html>
<html> 
<body> 
	<form name="Application" method=post action="/phpBB3/test.php" >
		Name:<input type="text" name="Name" size=20 maxlength=15>
		<input type="submit" value="Apply"> 
	</form> 
</body>
</html>

Code: Select all

<?php 
define('IN_PHPBB', true);   
$phpbb_root_path = './'; 
$phpEx = substr(strrchr(__FILE__, '.'), 1); 
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); 
include($phpbb_root_path . 'includes/bbcode.' . $phpEx); 
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
include ($phpbb_root_path . 'includes/functions_display.' . $phpEx); 
$user->session_begin(); 
$auth->acl($user->data); 
$user->setup('viewforum'); 
$allow_bbcode = 1; 
$allow_smilies = 1; 
$allow_urls = 1;  

echo utf8_normalize_nfc(request_var('Name', '', true));  
//echo $_POST['Name'];  

?> 
User avatar
Wolfsblvt
Registered User
Posts: 634
Joined: Sun Oct 26, 2014 9:12 pm
Location: Solingen, Germany
Contact:

Re: request_var won't accept unicode (even with multibyte set)

Post by Wolfsblvt »

request_var() is deprecated. In phpbb 3.1 you should use the request object wich should handle everything for you.
See here: https://area51.phpbb.com/docs/31x/codin ... ml#general

Maybe you should try to get this working.
If you have a specific extension request and you are willing to pay for, you can write me a PM.
My extensions (Trending: @Mention SystemAdvanced PollsUser Online Time)

»Du kamst zu uns. Deine Stimme kam. Du zeigtest uns die Sterne. Sie funkelten. Wir konnten sehen.«
Someone1234
Registered User
Posts: 4
Joined: Thu Jan 15, 2015 5:09 pm

Re: request_var won't accept unicode (even with multibyte set)

Post by Someone1234 »

I have migrated over, but it hasn't solved the core issue (or altered it). Same problem.

When I pass it a non-unicode it works.
When I pass it "Hêllo" it returns nothing ('').
is_set_post() seems to work as expected (with or without the unicode).

It doesn't even return "fail" as it might. Seems like this could be a bug.

Code: Select all

<?php 
define('IN_PHPBB', true);   
$phpbb_root_path = './'; 
$phpEx = substr(strrchr(__FILE__, '.'), 1); 
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); 
include($phpbb_root_path . 'includes/bbcode.' . $phpEx); 
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
include ($phpbb_root_path . 'includes/functions_display.' . $phpEx); 
$user->session_begin(); 
$auth->acl($user->data); 
$user->setup('viewforum'); 
$allow_bbcode = 1; 
$allow_smilies = 1; 
$allow_urls = 1;  
 
global  $request;
if ($request->is_set_post('Name'))
{
	echo 'Exists <br />'; 
}
  
$Name =  $request->variable('Name', 'fail', true, \phpbb\request\request_interface::POST); 
echo $Name; 
 
//echo utf8_normalize_nfc(request_var('Name', '', false));   
//echo $_POST['Name'];  

?> 
HJW
Registered User
Posts: 28
Joined: Thu Feb 12, 2009 11:50 pm
Contact:

Re: request_var won't accept unicode (even with multibyte set)

Post by HJW »

I'm not sure if I understood your problem. This works for me:
$name = utf8_normalize_nfc($request->variable('name', '', true));
Someone1234
Registered User
Posts: 4
Joined: Thu Jan 15, 2015 5:09 pm

Re: request_var won't accept unicode (even with multibyte set)

Post by Someone1234 »

It works for you with Hêllo within the 'name'? it works fine for me with non-unicode (e.g. "test") it is just when I have that special latin 'ê' it breaks. Even with utf8_normalize_nfc() the $request->variable() returns an empty string.
HJW
Registered User
Posts: 28
Joined: Thu Feb 12, 2009 11:50 pm
Contact:

Re: request_var won't accept unicode (even with multibyte set)

Post by HJW »

Yes, it works. Where are the post from. Is the site coding in UTF8-without BOM?
User avatar
RMcGirr83
Former Team Member
Posts: 21909
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: request_var won't accept unicode (even with multibyte set)

Post by RMcGirr83 »

check your third parameter with $request_var. It should be set to true for multibyte
doc blocks wrote: * @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
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 beerImage
Someone1234
Registered User
Posts: 4
Joined: Thu Jan 15, 2015 5:09 pm

Re: request_var won't accept unicode (even with multibyte set)

Post by Someone1234 »

edit:

You were right. The problem had absolutely nothing to do with PHPBB at all. The submitting form was corrupting the unicode because it lacked:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

Once I fixed the HTML form PHP could read the unicode strings correctly.
User avatar
RMcGirr83
Former Team Member
Posts: 21909
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: request_var won't accept unicode (even with multibyte set)

Post by RMcGirr83 »

$Name = utf8_normalize_nfc(request_var('Name', '', true);
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 beerImage
dnkroz
Registered User
Posts: 1
Joined: Wed Sep 23, 2015 6:56 pm

Re: request_var won't accept unicode (even with multibyte set)

Post by dnkroz »

Hi!
I have the same problem but I can't use UTF-8.

I have a declaration:

Code: Select all

<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"> 
And variable:

Code: Select all

$nazwa_imprezy_2= $request->variable('nazwa_imprezy_2', '', true, \phpbb\request\request_interface::POST);
Sending character like:

Code: Select all

ę

Gives me this:

Code: Select all

nazwa_imprezy_2:(unable to decode value)
Any suggestions?
Post Reply

Return to “Extension Writers Discussion”