Re: Handling HTML special chars from user generated content ( e.g. forms)

2008-08-29 Thread Mark (Germany)

i dont see the reason for changing them to HTML code anyway - as with
utf8 they can all be handled and displayed as they originally are.


On 28 Aug., 17:46, worthy [EMAIL PROTECTED] wrote:
 You saved my day. :D

 I was messing with this problem the whole day and never thought it
 would be that simple :).

 Thank you so much for this simple solution!

 Greetings
 worthy

 On 28 Aug., 17:38, Günther Theilen [EMAIL PROTECTED] wrote:

  Hi,

  do you use the form helper?
  If so try something like this:

  $form-input('foo.bar', array('escape' = false))

  Regards
  Guenther

  worthy schrieb:

   Another explaining example for the edit form:

  http://localhost/regions/edit/15

   data['Regions']['id']=15
   data['Regions']['name']='Test auml;'

   Now when cakephp fills the form with this data the value of the field
   changes from

   'Test auml;' to 'Test amp;auml;'

   And so the field shows 'Test auml; instead of 'Test ä'

   Is there any way to tell cakephp not to check for specialchars?

   Maybe now there is some help? :P

   Greetings
   worthy


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Handling HTML special chars from user generated content ( e.g. forms)

2008-08-28 Thread worthy

Hi bakers,
as by the last week i am really getting into CakePHP and enjoy the
easeness of the creation process.

But i have one simple problem.
In every form of the project where users can input data, they can for
example input ( ä,ö,ü, é... and special chars like %§%/ or whatever)

So i want to write a system function that converts all these chars to
their html form. That is for example a ä becomes auml; etc.

To approach this i already wrote a function that does this exactly:

function htmlizeArray($txtArray) {
if (is_array($txtArray)) {
foreach ($txtArray as $key = $val) {
htmlizeArray($val);
}
}
else {
$txtArray = htmlentities($txtArray);
}
}

So now i have to know where to put this function in the source to
access it from every controller that i have made.
Because in the controllers where i anyhow deal with posted form data i
want to htmlize the data.

All the form data from a specific view is in the controller accessed
by $this-data.

So what i want to do now is to htmlize it with

htmlizeArray($this-data);

So maybe you can help me out with it.

Greetings from Germany
worthy
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Handling HTML special chars from user generated content ( e.g. forms)

2008-08-28 Thread worthy

Hi bakers again :),
i managed to do it another way.

These two function provided below are the key for it. As you can see I
placed them inside of the app_controller.php



class AppController extends Controller {

function htmlchars($data) {

if (empty($data)) {
return $data;
}

if (is_array($data)) {
foreach ($data as $key = $val) {
$data[$key] = $this-htmlchars($val);
}
return $data;
}
else {
$patterns = array(/\/, /%/, //, //, '//', 
/'/, /\
(/, /\)/, /\+/, /-/, /ä/, /Ä/, /ö/, /Ö/, /ü/, /Ü/);
$replacements = array(amp;, #37;, lt;, gt;, 
quot;,
#39;, #40;, #41;, #43;, #45;, auml;, Auml;,
ouml;, Ouml;, uuml;, Uuml;);
$data = preg_replace($patterns, $replacements, $data);
return $data;
}
}

function unhtmlchars($data) {

if (empty($data)) {
return $data;
}

if (is_array($data)) {
foreach ($data as $key = $val) {
$data[$key] = $this-unhtmlchars($val);
}
return $data;
}
else {
$patterns = array(/amp;/, /#37;/, /lt;/, 
/gt;/, /
quot;/, /#39;/, /#40;/, /#41;/, /#43;/, /#45;/, /
auml;/, /Auml;/, /ouml;/, /Ouml;/, /uuml;/, /Uuml;/);
$replacements = array(, %, , , '', ', 
(, ), +,
-, ä, Ä, ö, Ö, ü, Ü);

$data = preg_replace($patterns, $replacements, $data);
return $data;
}
}

}

So if i retrieve any data for a view i simply do $cleandata = $this-
htmlchars($this-data); and use $cleandata for now on.
The same with unhtmlchars().



The only problem i have now is the following.

Lets say I have an edit form with a Name field.
If the Name contains no special chars like ä,ö,ü etc. the value
of the field is filled automatically through the $form helper, but if
the Name contains one of those special chars, the field is not filled.

I don't know how to solve this.

Please help me as I'm stuck here.

Thanks in advance
worthy
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Handling HTML special chars from user generated content ( e.g. forms)

2008-08-28 Thread worthy

Another explaining example for the edit form:

http://localhost/regions/edit/15

data['Regions']['id']=15
data['Regions']['name']='Test auml;'

Now when cakephp fills the form with this data the value of the field
changes from

'Test auml;' to 'Test amp;auml;'

And so the field shows 'Test auml; instead of 'Test ä'

Is there any way to tell cakephp not to check for specialchars?

Maybe now there is some help? :P

Greetings
worthy
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---