Solved Apostrophe problem with display type field

AlainR

Member
In a display field, I concatenate several fields and when one of these fields contains ' this causes an error, as if this apostrophe was considered a separator in the SQL query.
Code:
Une erreur est survenue

    0 syntax error, unexpected identifier "Arve"

Call stack
#     Function     Location
1     ()     JROOT/libraries/fabrik/fabrik/fabrik/Helpers/Php.php(69) : eval()'d code:17
2     Fabrik\Helpers\Php::createFunctionInMemory()     JROOT/libraries/fabrik/fabrik/fabrik/Helpers/Php.php:186
3     Fabrik\Helpers\Php::getClassName()     JROOT/libraries/fabrik/fabrik/fabrik/Helpers/Php.php:46
4     Fabrik\Helpers\Php::Eval()     JROOT/components/com_fabrik/models/element.php:1432
5     PlgFabrik_Element->getDefaultValue()     JROOT/plugins/fabrik_element/display/display.php:147
6     PlgFabrik_ElementDisplay->getDefaultOnACL()     JROOT/plugins/fabrik_element/display/display.php:162
7     PlgFabrik_ElementDisplay->getValue()     JROOT/plugins/fabrik_element/display/display.php:107
8     PlgFabrik_ElementDisplay->renderListData()     JROOT/components/com_fabrik/models/list.php:1289
9     FabrikFEModelList->formatData()     JROOT/components/com_fabrik/models/list.php:1063
10     FabrikFEModelList->finesseData()     JROOT/components/com_fabrik/models/list.php:958
11     FabrikFEModelList->getData()     JROOT/components/com_fabrik/models/list.php:735
12     FabrikFEModelList->render()     JROOT/components/com_fabrik/views/list/view.base.php:437
13     FabrikViewListBase->display()     JROOT/components/com_fabrik/views/list/view.html.php:46
14     FabrikViewList->display()     JROOT/administrator/components/com_fabrik/controllers/list.php:156
15     FabrikAdminControllerList->view()     JROOT/libraries/src/MVC/Controller/BaseController.php:693
16     Joomla\CMS\MVC\Controller\BaseController->execute()     JROOT/administrator/components/com_fabrik/fabrik.php:104
17     require_once()     JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:71
18     Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher\{closure}()     JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:73
19     Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch()     JROOT/libraries/src/Component/ComponentHelper.php:361
20     Joomla\CMS\Component\ComponentHelper::renderComponent()     JROOT/libraries/src/Application/AdministratorApplication.php:143
21     Joomla\CMS\Application\AdministratorApplication->dispatch()     JROOT/libraries/src/Application/AdministratorApplication.php:186
22     Joomla\CMS\Application\AdministratorApplication->doExecute()     JROOT/libraries/src/Application/CMSApplication.php:293
23     Joomla\CMS\Application\CMSApplication->execute()     JROOT/administrator/includes/app.php:61
24     require_once()     JROOT/administrator/index.php:32
The content of the text field does not cause any error, the error occurs only when the display field displays. If I correct the data by replacing the apostrophe with ’, the display is OK. So, in my display code, I tried a str_replace but it doesn't work, the error is always the same.
Code:
$champs = str_replace(''','’',$champs);
I also tested the proposed code here https://fabrikar.com/forums/index.p...encoding-when-display-only.52173/#post-272360 and here https://fabrikar.com/forums/index.p...apostrophe-on-fabrik-forms.51239/#post-267676 but without more success.
Is it a bug? Does anyone have any idea a solution?

Solution: use calc field for the element, thank you @troester
 
Last edited:
I concatenate 3 fields and calculate a date interval:
Code:
$champs='';$nb_jours = round((strtotime('{calendar___start_date_raw}') - strtotime('{calendar___end_date_raw}'))/(60*60*24)-1);$nb_jours=$nb_jours*(-1);
if($nb_jours>1){$nb_jours=$nb_jours.' jours';}else{$nb_jours=$nb_jours.' jour';}
$champNom='{calendar___Nom}';$champPrenom='{calendar___Prenom}';$champNomSoc='{calendar___NomSociete}';//problème d'apostrophe/**/
if($champNom){$champs=$champNom;}
if($champNom && $champPrenom){$champs.=' '.$champPrenom;}elseif($champPrenom){$champs=$champPrenom;}
if($champs){$champs.=' - '.$champNomSoc;}else{$champs=$champNomSoc;}
$champs = str_replace("'","’",$champs);
return $champs.' ('.$nb_jours.')';
 
Yup, a ' in an element placeholder quoted with ' won't do.
If you are sure the element won't contain a doublequote you can do "{your-element}".

But not sure what you are trying to do.
For concatenating other elements you better use the calc element
 
You're right, calc field is better.
Since I had problems with the calc field when I started coding this part and it worked with the display field, I did not try the calc field again. Obviously, it was a mistake because now my code in the calc field works perfectly! Thank you!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top