Zend form Label does not render with accents - zend-framework

I am trying to render a form which contains accents in the setlabel method like:
$ticketNumber->setLabel("Endereço");
I have tried every single option out there from forums. but it does not work, it displays the &atilde instead of the true value of that entity.
I addition. if i try the following, the text for the label does not render(the label is blank) at all.
$ticketNumber->setLabel("Endereço");
In my application.ini have added the following:
resources.view.encoding = "ISO-8859-1"
I really don't know what is wrong. I've been fighting this for couple of days now.
Any help is welcomed.
thank you.

$ticketNumber->setLabel("Endereço");
is correct. But you're then telling it to use an encoding where ç is not a valid character. You need to switch that to UTF-8 or similar:
resources.view.encoding = "UTF-8"

Related

Zend Framework Form not rendering special characters like (ä, ö, ü etc) - makes the form element value empty

I am trying to set the Zend Form working for me. I am using the same form for inserting and editing a particular database object. The object has name and I can easily create a new object with the name "Ülo". It saves correctly in database and when I fetch it to display in a report then it shows correclty "Ülo". The problem is with forms. When I open the edit form then the name element is empty. All other elements are showing correctly and if I change them to have "ü" in them they are displayed empty too. The same thing is with Form element labels. When I set a label to contain "ü" it does not show the label any more.
For example if I have $name->setLabel('Nameü: '); then it does not show the label but when I change it back to $name->setLabel('Name: '); then it shows correclty.
Same thing when I have $bcrForm->name->setValue('Ülo'); it does not show the value but when I change it to $bcrForm->name->setValue('Alo'); it shows correctly.
How can I fix it to display correctly? It seems like it is some kind of form rendering issue.
This one helped solving it for me:
make sure these settings are in /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini:
default_charset = utf-8
Did you checked encoding? Try adding this to head...
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
make sure that both your script and view files are encoded on UTF-8 and your connection to your DB is set for UTF-8 too.
If you are using mysql you force it to return UTF-8 data by openning a DB connection and running : SET NAMES 'utf8'
or using mysqli with : mysqli_set_charset('utf8');
I would check:
view charset
database charset (backend)
Zend_Db_Adapter charset
file charset
The view escape method is set to expect utf8 chars and may strip anything else (ie. singlebyte strange chars) :)
It should be as simple as setting escape flag to false on the elements label decorator.
$name->addDecorator('Label', аrray('escape'=>false));
Or see setEscape(). http://framework.zend.com/manual/1.12/en/zend.form.standardDecorators.html

Howto make JRequest::getVar filter correctly accented characters?

I want to filter some variables with accented character on a component for joomla1.5 for example:
$name = JRequest::getVar('name', '', 'post','WORD');
but the getvar function filters áéíóú. I need this get well for a form in spanish language.
I'm new to joomla development, but for as far as I can see, it doesn't let me set any other parameter to config to get this.
Is there a way to do this with the advantage of filtering with JRequest::getVar or should I create a function myself which does so?
Do you mean JRequest::getVar() removes symbols like 'áéíóú'? It is very weird because I've worked on Joomla with danish and hebrew symbols. And they were passed through GET, POST, SESSION successfully. Because Joomla works with UTF8 and it understands such symbols. The problem could be only in your file encoding. They should be in UTF8. Is it so? If not try to change it. This should help.

How to make Zend_Form display special characters in text elements?

I am using a Zend_Form subclass to add and edit records in a database. The layout has iso-8859-1 encoding and charset. The table records use latin1_spanish_ci collation.
The form input text element doesn't display anything at all when the record contains special characters like accents. If there are no special characters the form input text element displays the record correctly. Curiously enough the special characters display correctly when they appear outside the text input field, for example inside an Html heading2 or a paragraph.
I have tried inserting the following in application.ini:
resources.db.params.charset=iso-8859-1
but I get an error message:
SQLSTATE[42000] [1115] Unknown character set: 'iso-8859-1'
I have also tried changing the db charset to utf8 in the same way. The form text element displays the string but I get strange characters instead of the original ones.
I have tried almost anything but I haven't solved the problem. It seems that text input elements generated with Zend_Form hate Latin characters.
Have you had the same problem?
I found this simple solution in a zf forum:
Add the following to your _initView function in bootstrap.php and forget about everything else:
$view->setEncoding('iso-8859-1');

Apostrophe issue in RTF

I have a function within a custom CRM web application (old VB.Net circa 2003) that takes a set of fields from a database and merges them with palceholders in a set of RTF based template documents. These generate merged letters and documentation. The code essentially loops through each line of the RTF template file and replaces any instances of the placeholder values with text from a database record. The issue I'm having is that users have pasted a certain type of apostrophe into the web app (and therefore into the database) that is not rendering correctly in the resulting RTF file. It is rendering like this - ’.
I need a way to spot this invalid apostrophe in the code and replace it with a valid one. Unfortunately when I paste the invalid apostrophe into the Visual Studio editor it gets converted into the correct one. So I need another way to express this invalid apostrophe's value. Unfortunately I do not know a great deal about unicode and other encodings so I'm calling out for help with this.
Any ideas?
If you really just want to figure out what the character is you might want to try and paste it into a text editor like ultraedit. It has a hex mode that you can flip to to see the actual underlying bytes.
In order to do the replace once you've figured out the character you'd do something like this in Vb,
text.Replace(ChrW(2001), "'")
Note that you might not be able to figure it out easily using the text editor because it might also get mangled by paste from the clipboard. You might want to either print some debug of the ascii values from code. You can use the AscW function to do that.
I can't help but think that it may actually simply be a case of specifying the correct encoding to use when you write out the stream though. Assuming you're using a StreamWriter you can specify it on the constructor. I'm guessing you actually want ASCII given your requirement.
oWriter = New System.IO.StreamWriter(path, False, System.Text.Encoding.ASCII)
It looks like you probably want to encode characters out of the 8 bit range (>255).
You can do that using \uNNNN according to the wikipedia article.

HtmlEncode UTF-8

I'm using Server.HtmlEncode on a utf-8 string in asp-classic, which works fine until there are some accents in the string e.g. Rüstü Recber, which appears as Rüstü Recber (Rüstü Recber in the source).
I've tried setting the Response.Charset property to utf-8 but this doesn't make any difference.
Update (Solved): Adding <%#CODEPAGE=65001%> at the start of the page corrected the problem (http://technet.microsoft.com/en-us/library/bb742422.aspx)
Many thanks for all of the suggestions.
Check if the editor you are using to view the text is set to show utf-8.
Did you try to UrlEncode as well?
Are you sure that the string is correct before it is passed to HtmlEncode ? It looks like the string might be encoded wrong before it is passed to HtmlEncode.
Try to encode a string that you know is correct, and see if it is encoded correctly.