Use a field value in php formular to compare with another caracter chain

04greg1980

New Member
Hello,
I would like to use on an another page of my website an information of a field text in a php code.
I would like to compare the field text to another text.
I have try this code:

<?php
$x = "News";
$y ='{soumission___type}';
echo $y;echo $x;
// Compare $x and $y
if (strcmp($x,$y) == 0) {
echo 'Same content';
}
else {
echo 'Different content';
}

But the answer is always "Different content" as if $x is really igual to $y.

Have you a solution?
Thanks a lot
Greg
 
Try $y ='{soumission___type_raw}';

And if ($x === $y) {

Also, instead of "echo" you should use "return" in most places of Fabrik like calc elements, validations etc.
 
For debugging you shouldn't use echo but var_dump, so e.g.
var_dump($x,$y,strcmp($x,$y));
This will show you the type of variables and (in case of strings) the string length.

Where are you using this code?
 
Hello,
I try to modify the mpdf template.
I would like show only some informations, depending of a dropdown selection.
I explain. If the user select "New" into the dropdown and generate the pdf, I would like to change the color of the page title, for exmaple.
So I try to found a solution to transform the default.php file present in .../components/com_fabrik/views/details/tmpl/.../default.php.
So I try this code:

<?php
$x = "Nouvelle";
$y ='{soumissionnvlledemande___type_de_la_demande_raw}';
var_dump($x,$y,strcmp($x,$y));
// Compare $x and $y
if (strcmp($x,$y) == 0) {
echo 'Same content';
}
else {
echo 'Different content';
}

And the result is:
/volume1/web/.../components/com_fabrik/views/details/tmpl/boot/default.php:57: string(8) "Nouvelle" /volume1/web/.../components/com_fabrik/views/details/tmpl/boot/default.php:57: string(49) "Nouvelle" /volume1/web/.../components/com_fabrik/views/details/tmpl/boot/default.php:57: int(-45) Different content

It seems that strcmp was not done correctly, not on the raw data. How can I change that?

Thanks a lot for your help.
Greg
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top