1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

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

Discussion in 'Community' started by 04greg1980, Apr 17, 2021.

  1. 04greg1980

    04greg1980 New Member

    Level: Community
    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
     
  2. juuser

    juuser Well-Known Member

    Level: Community
    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.
     
  3. 04greg1980

    04greg1980 New Member

    Level: Community
    Thanks for your answer, but I have the same result.
    Another idea?
    Thanks
     
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
    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?
     
  5. 04greg1980

    04greg1980 New Member

    Level: Community
    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
     
  6. troester

    troester Well-Known Member Staff Member

    Level: Community
    Last edited: Apr 18, 2021
  7. 04greg1980

    04greg1980 New Member

    Level: Community
    Hello,
    Thanks a lot.
    I have success to do what I want with your link.
    See you
     

Share This Page