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.

autoprefix urls with http:// for user supplied links in a links page

January 31, 2008 8:59am

Subscribe [3]
  • #1 / Jan 31, 2008 8:59am

    Jan_Huygens

    106 posts

    In one site, members can add links to a links page - they supply the url to an external site, the link text and a brief description. The info is held in the fields {f_link_url}, {f_link_text} & {f_link_desc} respectively.

    Sometimes users enter the url in the form:

    <a href="http://www.goodsite.com">http://www.goodsite.com</a>
    and sometimes in the form
    <a href="http://www.goodsite.com">http://www.goodsite.com</a>

    If I just use the EE code

    <a href="http://{f_link_url}" title="{f_link_desc}">{title}</a> {f_link_text}

    then I have a problem with the first form, as EE generates an internal link to a none existant page, rather than to the true external site :-(

    So my question is: Is there a simple way in EE to force to prefix the contents of {f_link_url} with ‘http://’ if needed?

    BTW I dont want to use the option in weblog admin to ‘automatically turn urls ..into links’, as this uses the url for the link text, which can look extremely messy when the page is from other CMS’s.

  • #2 / Jan 31, 2008 9:18am

    Mark Bowen

    12637 posts

    Hmm,

    I think you are going to need to use PHP on that or create a plugin to do what you need. On the other hand, where are the users inputting this information. If it is through a Stand-Alone Entry Form or any other place other than the control panel then you could use some javascript regex validation on the field to make sure that they put in the http:// bit. The best Javascript validation routine I have ever come across is Live Validation.

    That would work for you.

    Hope that helps?

    Best wishes,

    Mark

  • #3 / Jan 31, 2008 9:21am

    Jan_Huygens

    106 posts

    Hi Mark and thanks for the quick reply

    I was afraid that that might be the answer ... sigh

  • #4 / Jan 31, 2008 9:25am

    Mark Bowen

    12637 posts

    Not the only answer though. I will have more of a think on this one. I just wrote what I did really fast as I am in the middle of recording a radio advert so didn’t have a lot of time!! 😊

    Will have more of a thought about this later on.

    Best wishes,

    Mark

  • #5 / Jan 31, 2008 9:31am

    Jan_Huygens

    106 posts

    thanks 😊

    BTW has your avatar just changed?
    the hair looks spikier somehow

  • #6 / Jan 31, 2008 9:32am

    Sue Crocker

    26054 posts

    One other option is to check the value of the field for the text string of http:// (first 7 characters) and if they aren’t http:// pre-pend http:// to the field.

    Another possible plugin.

    I’m not a plugin person - (I’ve only written two of them), but I know I’d use it. Clients frequently don’t put in data correctly.

  • #7 / Jan 31, 2008 9:38am

    Jan_Huygens

    106 posts

    Sadly I’m not a plugin person either.

    I had thought about that approach, but thought that I should check first before trying to re-invent the wheel.

    BTW It wasn’t just customers entering data wrongly 😊 I spotted it after entering a new link myself!

  • #8 / Jan 31, 2008 10:02am

    Mark Bowen

    12637 posts

    BTW It wasn’t just customers entering data wrongly 😊 I spotted it after entering a new link myself!

    Tut tut that will never do!! 😊

    I will just have to write you a plugin then won’t I? 😉

    May have to be later on tonight as I am stacked out with work at the moment but will give this a shot for you!

    Best wishes,

    Mark

  • #9 / Jan 31, 2008 10:08am

    Jan_Huygens

    106 posts

    Brilliant 😊

    Thats really kind and very much appreciated indeed.

  • #10 / Jan 31, 2008 10:33am

    Sue Crocker

    26054 posts

    Mark, in your copious free time, a Complete Beginner’s Guide to Writing Your First Plugin would be a *great thing*.

  • #11 / Jan 31, 2008 11:09am

    Mark Bowen

    12637 posts

    Copious free time? You must be joking!! 😊

    I do have 25 pairs of hands though. Slight problem as I only have the one brain!!

    Best wishes,

    Mark

  • #12 / Jan 31, 2008 12:27pm

    Mark Bowen

    12637 posts

    Hi Jan,

    Just to let you know that I am pretty sure I have something working now. I will upload it tonight once I get back from my in-laws as I need to go and fix a computer!
    Will test it out thoroughly as well but I am almost certain it will do what you need it to! 😊

    Best wishes,

    Mark

  • #13 / Jan 31, 2008 1:02pm

    Jan_Huygens

    106 posts

    I’m looking forward to trying out your latest lifesaver.

    You really are a master of multi-tasking - may your 25 hands never grow less 😊

  • #14 / Jan 31, 2008 3:07pm

    Mark Bowen

    12637 posts

    Well the time comes for me to unleash another plugin on the ExpressionEngine world!! 😊

    Neat Link. I really do need to start thinking up some better names for these things though.

    Hope it works for you Jan.

    Best wishes,

    Mark

  • #15 / Jan 31, 2008 3:45pm

    Jan_Huygens

    106 posts

    It does indeed. 😊

    What more can I say? [cept of course, thanks!!]

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

ExpressionEngine News!

#eecms, #events, #releases