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.

Check Custom Field for Specific Text

June 25, 2012 8:59pm

Subscribe [1]
  • #1 / Jun 25, 2012 8:59pm

    ctrlaltdel

    119 posts

    Is there a way, either out-of-the-box or via PHP, to check if a custom text field contains a particular bit of text, and if it does not, add it in when rendering the template?

    For example, I have a custom field for “website” where I’d like the content editors to always add “http://” before they enter a URL. But, if they forget to add the “http://”, I’d like to add it for them when the template is rendered.

    Thanks!

  • #2 / Jun 26, 2012 12:58am

    PhilBrienesse

    187 posts

    http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#search-field-name

    That would be one option but it basically filters entries that the field either does or doesn’t contain the specific text you could then add it in in your template and then do a seperate call for ones that had the http:// this may not work great though if they need to be in a specific order.

    http://www.causingeffect.com/software/expressionengine/ce-string/user-guide CE String is an incredible addon that lets you run all kinds of php manipulation.

    If your given example was actually what you are trying to do you may want to try either

    http://devot-ee.com/add-ons/jco-url or http://devot-ee.com/add-ons/vz-url-extension

  • #3 / Jun 26, 2012 6:58am

    ctrlaltdel

    119 posts

    Thanks, Phil! I’ll take a look. I appreciate the help.

  • #4 / Jun 26, 2012 8:24pm

    ctrlaltdel

    119 posts

    FWIW, I think I might have been able to write a small PHP snippet to do the check for me. It looks like it works for the data set that I currently have.

    {if company_url}
    <?php
      $url = '{company_url}';
      if (strpos($url,'http://') !== false) {
        print $url;
      } else {
        print 'http://'.$url;
      }
    ?>
    {/if}

    My limited PHP knowledge seems to have gotten me to where I needed to be!

    Thanks again.

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

ExpressionEngine News!

#eecms, #events, #releases