"Email this page" in CMS Builder page?

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 6, 2008   (RSS)

By matrix - April 4, 2008

Feeling not so smart here...tried everything I could think of but am having no luck creating an "Email this page" link for the news pages.

Here's the last link format I tried within the newsPage.php template:
<a href="mailto:?subject=<?php echo $record['headline'] ?>&body=<?php echo $record['_link'] ?>">

I had included the Record List code above that, which works so well with internal menus.

The headline is called nicely, although cut short, but I can't get the doggoned URL to display in the email subject.

Also tried <? echo $PHP_SELF; ?>, before figuring out all needed to be called through fields somewhere (is that right?).

How to do this, please?

Many, many thanks.
Happy Interactive Tools product user since 1999

Re: [matrix] "Email this page" in CMS Builder page?

By Dave - April 5, 2008

What is it outputting right now when you view source?

mailto: links can be a little tricky and are sometimes handled differently by different mail programs. Here's two things to watch for:

You often need to url encode the values. Otherwise, if there's a = or & in the headline the browser might get confused with the link. Url encodes uses sequences like this %3D (that's a =) to represent characters that otherwise have a special meaning in the url. You can add the PHP urlencode() function to your tag like this to automatically url encode:

<?php echo urlencode($record['headline']) ?>

This will display "this & that" as "this%20%26%20that".

Next, if the full link with HTTP isn't appearing you may need to add that. The simplest way is just to add it manually:

...&body=http://example.com/path/to/viewerDir/<?php echo $record['_link'] ?>"

If you want to get it automatically you could try something like this before the _link (assuming the link doesn't already include the http:// part):

<?php echo "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" ?>

There's no variable with the full url so we need piece it together from those others.

Hope that helps. If you need any more details or if that doesn't quite do it just let me know! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] "Email this page" in CMS Builder page?

By matrix - April 6, 2008

Thank you so much for your quick response.

It definitely helped, but no go, yet. I think we've narrowed it down to the record link issue.

I've tried both solutions, multiple times, multiple ways, and neither is writing the <?php echo $record['_link'] ?>.

Here are the solutions that came closest, with the error messages returned (using generic URLs here as example):

__________________
ONE -
<a href="mailto:?subject=<?php echo urlencode $record['title']?>&body=http://RightDomain.com/RightDirectory/<?php echo urlencode $record['_link']?>>"Click here to email page.</a>

ERROR MESSAGE RETURNED BY BROWSER:
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' i

SECOND ATTEMPT (after reading up a little at http://us3.php.net/urlencode and adding parentheses)

<a href="mailto:?subject=<?php echo urlencode ($record['title'])?>&body=http://RightDomain.com/RightDirectory/<?php echo urlencode ($record['_link'])?>>"Click here to email page.</a>

ERROR MESSAGE IN SOURCE CODE:
<a href="mailto:?subject=The+Article+Title&body=http://RightDomain.com/RightDirectory/<br />
<b>Notice</b>: Undefined index: _link in <b>/RightPath/articlesPage.php</b> on line <b>113</b><br />
>"Click here to email page.</a>
___________________________

I even made sure to reload the "Records List" code above the Email Page code, figuring the page couldn't see the variable unless that happened, but no luck.

It feels so close, and I know we're spoiled by the ease with which you have made this happen in Article Manager:
<a href="mailto:?subject=$art_name_ue$&body=$url_thispage_ue$">

Is it possible to have the full code written out using the generic example above for those of us whose PHP expertise is light years behind yours? This surely is a super-useful snippet many of us will use.

Many, many, many thanks again.

M

PS: I never realized how beautiful your little $url_thispage_ue$ was until now. Thank you for that one! It's now in use on thousands of pages for our sites and those of clients.
Happy Interactive Tools product user since 1999

Re: [matrix] "Email this page" in CMS Builder page?

By Dave - April 6, 2008

Oh, ok. I think I was on the wrong track the whole time. I was thinking that you were working with the list viewer. But you're not you're working with the page viewer. Try adding this just below "getRecord":

$record = getRecord($options);

$thisPage = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?" . $record['num'];


It will define a variable called $thisPage that you can use like this: <?php echo $thisPage; ?>. I don't think you need to url encode it, but if you do, it would be like this: <?php echo urlencode($thisPage); ?>

I've made a note to add a $thisPage variable to an upcoming version. Thanks for the suggestion. I'm hoping this one works but do let me know if it's not quite right or there's any issues with the format of the url.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com