Help inserting web address link from record

12 posts by 2 authors in: Forums > CMS Builder
Last Post: July 12, 2008   (RSS)

By gkornbluth - July 5, 2008

I’m having a small challenge inserting a web address from a record on to a web page.

The record has a field for the URL called ”web_site”

the code on my web page looks like this:

<a href="<?php echo $record['web_site'] ?>"><?php echo $record['web_site'] ?></a>

If the field includes an http:// as part of the URL then all is well, and the link on the page points to the correct web address.

However, if the URL in the field does not start with http:// and instead starts with either www.theirsite.com or is just theirsite.com, then the link on the page points to http://myipaddress/www.theirsite.com or http://myipaddress/theirsite.com.

Any ideas how to fix this? (I can’t depend on the data entry people to always enter the data to include the http://)

Thanks

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Help inserting web address link from record

By Jake - July 6, 2008

Hi Jerry,

Try using this code to get around this problem:

<?php

if (preg_match('^/http:\/\/', $record['web_site'])) {

echo "<a href=\"$record['web_site']\">$record['web_site']</a>";

} else {

echo "<a href=\"http://$record['web_site']\">http://$record['web_site']</a>";

}
?>


Basically, what that's doing is checking for the presence of "http://" at the start of the text in this field. If it isn't found it's added in, otherwise the data is displayed as is.

Let us know how that works out for you. [:)]
-----------------------------------------------------------
Cheers,
Jake Marvin - Product Specialist
support@interactivetools.com

Hire me!
Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.

Re: [gkornbluth] Help inserting web address link from record

By Jake - July 7, 2008

Hi Jerry,

Try using this code instead and let us know how it works out:

<?php
// add http to website url if not there
if (!preg_match("/^http:\/\//", $record['web_site'])) {
$record['web_site'] = "http://" . $record['web_site'];
}
?>

-----------------------------------------------------------
Cheers,
Jake Marvin - Product Specialist
support@interactivetools.com

Hire me!
Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.

Re: [Jake] Help inserting web address link from record

By gkornbluth - July 7, 2008

Jake,
Thanks for looking at this. It seems that you're getting closer.

Now the site pulls up an http:// when it's not there in the database and displays it on the page.

As you can see at:

http://98.130.249.212/artists6.php

One problem, however.

The links all lead back to the originating page and the rendered html on the page looks like this:

<a href="">http://csite.com</a>

The php code in the page looks like this:

<a href="<?php
// add http to website url if not there
if (!preg_match("/^http:\/\//", $record['web_site'])) {
$record['web_site'] = "http://" . $record['web_site'];
}
?>"><?php echo $record['web_site'] ?></a>
The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Help inserting web address link from record

By Jake - July 7, 2008

Hi Jerry,

I took a look at your page here, but all of the links were working:

http://98.130.249.212/artists6.php

Would it be possible for you to add in a record that creates this problem so that I can take a look at it for you?
-----------------------------------------------------------
Cheers,
Jake Marvin - Product Specialist
support@interactivetools.com

Hire me!
Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.

Re: [Jake] Help inserting web address link from record

By gkornbluth - July 8, 2008

I’m sorry, It was a bit late at night and I forgot to update the post. I managed to find the error. Here’s the new code that I used.

I had been using the code that you ssuggested as a single call, like this:

<a href="<?php
// add http to website url if not there
if (!preg_match("/^http:\/\//", $record['web_site'])) {
$record['web_site'] = "http://" . $record['web_site'];
}
?>"><?php echo $record['web_site'] ?></a>

Instead I made it 2 separate calls, like this and it worked just perfectly:
div><?php
.
if (!preg_match("/^http:\/\//", $record['web_site'])) {
$record['web_site'] = "http://" . $record['web_site']; }
?>

<a href="<?php echo $record['web_site'] ?>"><?php echo $record['web_site'] ?></a> </div>

Thanks again for your help.
The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Help inserting web address link from record

By Jake - July 8, 2008

Hi Jerry,

No problem - I'm just glad you got everything working. [:)]
-----------------------------------------------------------
Cheers,
Jake Marvin - Product Specialist
support@interactivetools.com

Hire me!
Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.

Re: [Jake] Help inserting web address link from record

By gkornbluth - July 8, 2008

Now if I could only get the search functions working, I'd really be a happy CMSB user.

http://www.interactivetools.com/iforum/P63551#63551
The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Help inserting web address link from record

By Jake - July 8, 2008

Hi Jerry,

No problem - I did get your message and I'm reviewing that right now, so you should hear from me shortly. [:)]
-----------------------------------------------------------
Cheers,
Jake Marvin - Product Specialist
support@interactivetools.com

Hire me!
Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.