Forums

escape problem

lucadonati 31 May, 2012
Hello,
I show some data from the MySQL database in a Joomla (v 1.5.22) page and I have this code in ChronoForms (v 3.2):
<?php
$v_Languages = '{Languages}';
if ($v_Languages == "")
  $v_Languages = "";
else
  $v_Languages = '
<tr valign="top">
<td class="sx"><div align="right">Languages</div></td>
<td colspan="2">{Languages}</td>
</tr>
';
echo $v_Languages;
?>

then I use Chrono Connectivity (v2.0 RC3) to show the field data in the page.

I have an escape problem, for example when in the field data I have an apostrophe the code brokes and I don't visualize anything.
In fact, even the html should be encoded to be visualized properly.

Do someone knows how I can change the code, I guess with some php/mysql function to solve the problem?

Thank you

Luca
GreyHead 31 May, 2012
Hi Luca,

I'm sorry I don't understand exactlty what the problem is.
What is saved in the database?
What code are you using to display a result in ChronoConnectivity?

Bob
lucadonati 31 May, 2012
Hi GreyHead,
I try to explain myself better.

In ChronoConnectivity I first make e query to get some data:
WHERE `DepartmentID` = 42

then I call the form to display
<a href='index.php?option=com_chronocontact&chronoformname=project_management&CareerID={CareerID}'>{Title}</a>


The problem is that if, for example, in the field {Languages} in the example above I have a text like "I'm happy" the code breaks because the single quote, it should be "I\'m happy" but I don't know how to modify the following code to escape special and html characters in the php condition, I should probably use a php or MySQL function.
<?php
$v_Languages = '{Languages}';
if ($v_Languages == "")
  $v_Languages = "";
else
  $v_Languages = '
<tr valign="top">
<td class="sx"><div align="right">Languages</div></td>
<td colspan="2">{Languages}</td>
</tr>
';
echo $v_Languages;
?>

Can you help?

Thank you

Luca
GreyHead 27 Sep, 2012
Hi Luca,

I just found this again :-(

You could possibly use str_replace("'", "\'", $v_languages); but I'm not sure it would work. This might be better:
<?php
$v_Languages = '{Languages}';
if ( $v_Languages != "" ) {
  $v_Languages = "<tr valign='top' >
  <td class='sx'><div align='right'>Languages</div></td>
  <td colspan='2' >{$v_Languages}</td>
</tr>";
}
echo $v_Languages;
?>

Bob
This topic is locked and no more replies can be posted.