We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27716
    • 126 Posts
    Hi Guys,

    Whenever I add a link to my site without http:// it end up as a broken link.

    The link end up rendering as mydomainname.com/www.link.com

    So the link just appends to my domain and end up broken.

    Its a big issue for me as when users register and enter their website they often leave out the Http://

    Is this a common issue. Are there any easy fixes?
      • 5340
      • 1,624 Posts
      Hi,
      2 solutions

      1. Force you users to enter http. A simple javascript validation rule should do the trick
      2. When showing the url detect if the values has http or not. A simple snippet can do the trick

      I would choose the second is a lot more easier to do.
        • 27716
        • 126 Posts
        Thanks for the recommendation Cipa,

        Any guidance on writing that snippet smiley
          • 5340
          • 1,624 Posts
          Can you post your template in here? I need to understand how you do it before I do anything else
            • 27716
            • 126 Posts
            Hi Cipa,

            This is happening any time I use an anchor tag throughout the site.

            One example of how i’m using it in a template is below. IN this case its pulling the users website they enter on Registration.

            <span style="font-size:9px; ">Answer by: <a rel="nofollow" href="http://[[+createdby:userinfo=`website`]]" target="_blank">[[+createdby:userinfo=`username`]] </a></span>


            Stuart
              • 5340
              • 1,624 Posts
              This is not tested

              1. Create a snippet "AddHttp"
              2. Paste this code

              <?php
              
              //AddHttp
              $find   = 'http';
              $pos = strpos($website, $find);
              
              if ($pos === false) {
                  return 'http://' . $website;
              }
              
              return $website;


              3.in your template do something like

              href="[[AddHttp? &website=`[[+createdby:userinfo=`website`]]`]]"

                • 27716
                • 126 Posts
                Hey Cipa,

                Thanks so much for the guidance,

                Will try it tomorrow and let you know if it works.
                  • 27716
                  • 126 Posts
                  Finally had a chance to put this in place,

                  Worked a treat smiley

                  Thanks.

                  Stuart
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    Will people ever paste in a link with https?

                    May need to modify the snippet to check for either before prepending it to avoid accidently breaking it when they use ssl.
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                      • 27716
                      • 126 Posts
                      Hey Mark,

                      Good Idea, didn’t even cross my mind.

                      Will definitely try and code something in to prevent errors with Https URLs.

                      Stuart