Peter Knight

Can't link to external URL

Recommended Posts

Is I have a field called 'external_link' which accepts a url, is there an issue with the following code?

<a href="http://www.<?=$page->external_link?>">Visit site</a>

I've tried making the fieldtype both URL and Text and nothing seems to work and I send up with the following code when viewing source.

<a href="http://www">Visit site</a>

Normally I'd suspect that I named the field incorrcetly in my PHP or that the field isn't associated with the correct template etc. In this case, thats not the issue.

Share this post


Link to post
Share on other sites

Use either <?= or <?php echo instead "<?"

Share this post


Link to post
Share on other sites

That's not the issue 🙁 but thanks for spotting it.

The example I posted had a typo but the actual code used was correct.

<a href="http://www.<?=$page->external_link?>">Visit site</a>

 

Share this post


Link to post
Share on other sites

Ok, something is with your "$page->external_link", this quick test works fine here:

<?php
$page = new stdClass();
$page->external_link = 'processwire.com';
?>
<a href="http://www.<?=$page->external_link?>">Visit site</a>

Perhaps $page is not the page you would like to use?

What type of field is "external_link"?

  • Like 1

Share this post


Link to post
Share on other sites

Not related to your problem, but I wouldn't recommend inserting "http://www." like that for a few reasons:

1) A site editor could easily add that part themselves - especially if they copy from their browser address bar and then you would have it twice

2) The site may not work with with the www subdomain - unlikely, but possible

3) They might want to link to a different subdomain rather than the www one

4) The site might be https, not http - most likely it would redirect automatically, but it just feels wrong to try to force this

  • Like 2

Share this post


Link to post
Share on other sites

Thanks you both. It's working somewhat inexplicably now with no changes at my end 😕

I have a feeling a database and server backup which was running was affecting this. That's the only explanation I can think of.

 

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Thomas Diroll
      Hi guys I'm relatively new to PW and just finished developing a page for a client. I was able to include all necessary functionality using the core fieldtypes but now I it seems that I need to extend them with a custom one. What I need is a simple button, that copies the absolute url (frontend not PW-backend) of the page which is currently edited to the clipboard. As this feature is only needed inside a specific template, I tend to use a custom fieldtype which provides this feature. I've been looking inside the core modules code (eg. FieldtypeCheckbox.module) but I don't really get the structure of it and how its rendered to the admin page. I also didn't find a lot of tutorials covering custom fieldtypes.
      Maybe some of you could give me some tips on how to write a basic custom fieldtype that renders a button which copies the value of
      page->httpUrl() to the clipboard using JS. Thanks!
    • By BrendonKoz
      I began writing this module from scratch, basing it off simple examples of modules, trying to learn the necessary methods required to create a fieldtype. I was WAY off, but learned a lot. Eventually I moved towards examining the FieldtypeEvents example from Ryan and, in many areas, copy/pasting and then adjusting the code (and then trying to determine what it all was doing) method by method, file by file (from his example to my module).
      I've gotten to the point where I was ready to test the code - I haven't fully fleshed out my visual interface, nor integrated any of the 3rd party API tools this will (can) take advantage of. I also haven't implemented any JS or CSS for the interface. Right now I'm just trying to get it to save and then display any of the data that has been entered into the form fields of a template from the admin. When I save the page, the field is reset to defaults and no feedback message (for the field) is shown at the top of the page upon reload. When using Tracy Debugger from within the processInput method (immediately attempting to debug the $input variable), Tracy caught no data to be shown.
      If anyone has some time to take a quick look and see what I might've done wrong I'd be super grateful. I've had no forward progress in about 3 days (and like many others was unable to get Xdebug breakpoints working in PHPStorm). 😞
      https://github.com/BrendonKoz/FieldtypeBooks
    • By theoretic
      Hi there! And thanks for Processwire!
      Maybe i'm not very attentive but couldn't find any tutorial on creating custom fieldtype with custom inputfield. Would like to make one for selecting color(s) from predefined list of colors. The closest existing match is FieldtypeSelectOptions with InputfieldSelect but i need something different. There's a very good post from @Soma   which is, however, insufficient to begin building my own fieldtype or at least to attach the existing inputfield to an existing field.
      Will appreciate any help. Thanks in advance!
    • By Anna
      How to FieldtypePage category as blog?
      Home
          - receptek
                - recept
                - recept
                - recept
          - kategorak
               - kategoria
               - kategoria
               - kategoria
      recept.php <?php foreach($page->kat_page as $item) { //$item = kategoria echo "<h3>$item->title</h3>"; //kategoria->recept??? }  

    • By didhavn
      Hey all.
      I just came across a potential error in the FieldtypePassword.
      I have a password field added to some templates to protect the pages. However, whenever I want to save a page, I get the error of "required fiield missing"...that the password field is required and missing. But, the field is not set to required.
      Can anybody confirm that and/or has a solution?
      Best, Lukas