Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Phil Young 19 posts 39 karma points
    Jun 26, 2012 @ 11:12
    Phil Young
    0

    check user input string contains 'http://'

    Hi all,

    I've got 2 user input fields which allows users to select either an internal page via the content picker, or provide a url to an external page via a text string field. However I've noticed that if the user doesn't include http:// in the url they provide, it simply appends it to the current url as if it were a folder on the current site.

    What i'd like to do is check whether the text string contains 'http://' and if not, add it manually in the xslt. What would be a suitable way of doing this with xslt?

    Thanks in advance, Phil

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jun 26, 2012 @ 11:18
    Chriztian Steinmeier
    0

    Hi Phil,

    When you're about to output the value - do like this:

    <xsl:if test="not(starts-with($currentPage/externalLink, 'http://'))">
        <xsl:text>http://</xsl:text>;
    </xsl:if>
    <xsl:value-of select="$currentPage/externalLink" />

    It's not foolproof, but will catch most cases :-)

    /Chriztian

  • SC Digital Services Team 104 posts 171 karma points
    Jun 26, 2012 @ 11:53
    SC Digital Services Team
    0

    You might also want to look at uComponents, as this contains a URL Picker ( http://ucomponents.codeplex.com/wikipage?title=UrlPicker ) data type which will handle your 2 input fields within 1 interface.

Please Sign in or register to post replies

Write your reply to:

Draft