1

I allow members to enter their web address, facebook address, etc. for their member profiles as well as in directory listing entries. I instruct them to always include "http://" at the beginning of the URL but of course they don't always listen. So in many cases I'm getting URL formatted with no "http://" or "https://" which create bad links.

Is there a way I can essentially do a find a replace for NOT found? So if the URL string does not contain "http://" or "https://" then I can add it back in so the link isn't broken?

I use CE String plugin for other things and I have been trying to work out a way to use it for this purpose but haven't had any luck yet.

Here's the related part of my template:

{if website}<li class="web"><a href="{website}">{exp:low_replace multiple="yes" find="http://|https://"}{website}{/exp:low_replace}</a></li>{/if}
{if facebook}<li class="facebook"><a href="{facebook}">{exp:low_replace multiple="yes" find="http://|https://"}{facebook}{/exp:low_replace}</a></li>{/if}

I need to enter some logic at the beginning of each link's href to add in the "http://" if the member has not included it in their URL string. Would appreciate any help on how to achieve this.

1 Answer 1

2

The EECMS has a "first party" plugin for this, but it isn't included in ExpressionEngine by default. You have to download it.

From the own add-on file:

Makes sure that a URL has a protocol, that ampersands are converted to entities, and all other characters are properly URL encoded.

{if website}
    <li class="web">
        <a href="{exp:valid_url}{website}{/exp:valid_url}">
            {website}
        </a>
    </li>
{/if}
{if facebook}
    <li class="facebook">
        <a href="{exp:valid_url}{facebook}{/exp:valid_url}">
            {facebook}
        </a>
    </li>
{/if}

There's some useful add-ons available for download on the User Guide. They're all maintained by EllisLab itself.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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