ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Conditionals matching with apostrophe in string

April 11, 2012 5:44pm

Subscribe [2]
  • #1 / Apr 11, 2012 5:44pm

    Ian Young

    200 posts

    I’ve created a custom field and I’m using conditionals to match the value of that custom field. However one of the options contains an apostrophe (single quote) in the string. As a result of this it isn’t matching correctly. Here’s my code:

    <select name="order_custom2" id="order_custom2" class="select" tabindex="2" >
        <option value="Option One"{if order_custom2 == "Option One"} selected="selected" {/if}>Option One</option>
        <option value="Option Two" {if order_custom2 == "Option Two"}selected="selected"{/if}>Option Two</option>
        <option value="I'm Option Three" {if order_custom2 == "I'm Option Three"}selected="selected"{/if}>I'm Option Three</option>
    </select>

    Option One and Two match when when {order_custom2} is equal to either of those. Option Three never matches however even though if I just output {order_custom2} when it’s very is that of the third option it outputs

    I’m Option Three

    An exact match.

    I know in the documentation for conditionals that it makes mention of special characters but the apostrophe is not listed in the conversion list. I’ve also tried replacing the apostrophe with it’s HTML character entity code but there’s still no difference. When I test taking the apostrophe out it matches fine so it’s definitely something to do with that apostrophe but I just don’t know how to get it to match. I’ve tried HTML character entities and escaping with a backslash but neither have worked.

  • #2 / Apr 12, 2012 6:25am

    Ian Young

    200 posts

    Got it! Wrapping the field to check in quotes and brackets stops it from being escaped and parsed correctly in the conditionals:

    <option value="I'm Option Three" {if "{order_custom2}" == "I'm Option Three"}selected="selected"{/if}>I'm Option Three</option>

    Where would I be without the EE forums.

  • #3 / Apr 12, 2012 1:19pm

    Shane Eckert

    7174 posts

    Hey Slippy,

    I am glad to see that you got this resolved.

    If you need anything else, please just let us know by opening a new thread.

    Have a great week.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases