2

I'm fairly new to ExpressionEngine, and I hope the problem I'm running into is a simple one to solve. I'll try to illustrate it as best as possible:

I have a radio button field (created within a channel form) called favorite_food. It has 4 options, namely Pasta, Vegetables, Poultry, and Fruit. The form displays great, and submitted values are saved in the channel entries.

The problem comes in when I'm trying to display the results on another template, and specifically adding a conditional statement that checks if the user selected Fruit or not is causing me to go a little crazy. This is what I've tried:

{exp:channel:form channel="foods" entry_id="{segment_4}"}

    <!-- displays "Fruit" successfully -->
    <div>{favorite_food}</div> (displays Fruit on the screen)

    <!-- this does not display anything at all? -->
    {if favorite_food == "Fruit"}
        <div>You chose fruit!</div>
    {/if}

    <!-- even with PHP, this works great... -->
    <?php echo "{favorite_food}"; ?>

    <!-- ...but this also doesn't display anything at all? -->
    <?php
        if ("{favorite_food}" == "Fruit")
            echo "<div>You chose fruit!</div>";
    ?>

{/exp:channel:form}

I should mention that the PHP parsing is set to "input" on this template too. I hope I'm missing something really obvious here...thanks in advance for any assistance!

2

The radio field might need to be parsed like:

{if "{favorite_food}" == "Fruit"}
    <div>You chose fruit!</div>
{/if}

which makes it an advanced conditional (parsed later in parse order).

For php on input, the php is run before the ee tags get parsed. So when the template is parsed after the php was run your php statements would look like:

<!-- even with PHP, this works great... -->
{favorite_food}

<!-- ...but this also doesn't display anything at all? -->

So the first works. The second doesn't output anything (other than the comment) because {favorite_food} is evaluated as a string only instead of as an ee variable, and so as a conditional it's false. If on the other hand you had php set on output, the first would still work and the second should as well.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.