"Invite a Friend" populate fields?

For some reason the Javascript to "Post Reply" on the original forum post of this message doesn't work, so I've started a new one. This is what was said so far:

Hi everyone,

Is there a way to populate the fields of "Your Name" and "Your Email" with the login nickname and the associated email address when the "invite a friend" window opens, as this function only seems to work if these values correspond with the logged in profile.


Many people will not think to use their login name but would use their full name and possibly a different email address.


If these values don't correspond a "send email failed" message appears.

Can something be changed in the tellfriend.php to make this happen?

Thanks,

Wizard247

_________________________________________________________________

This was replied to by LeonidS:

Hello!


U may change this part in tellfriend.php code for placing FirstName field instead NickName:

this one:

$profileID = 0;

change to the following:

(int)$_COOKIE['memberID'] : 0


'name' => array(
'type' => 'text',
'name' => 'name',
'caption' => _t("_Your name"),
'value' => $sVisitorName
),

instead $sVisitorName u may enter $aVisitorInfo['FirstName'] for example.

Regard

_________________________________________________________________

My response follows below:


Thanks, LeonidS, a couple of problems with this approach:

Firstly: (int)$_COOKIE['memberID'] : 0 should be (int)$_COOKIE['memberID'] = 0 otherwise a parsing error occurs.

Secondly: when I implement your approach, the sender is only able to use his/her first name. When the email then hits the inbox of the recipient, they are not really going to know who the email is from, if for instance, the first name is a common name like "John" or "Joe". A similar problem of course occurs when the default nickname is used.

So, is there a way to include BOTH firstname and surname fields and have the emails signed with both of them?

Also, although this is a helpful reply, it didn't really answer my question - I gather therefore that it is NOT possible to prefill the fields?

I've adjusted the language file to prompt users to use their login name and their registered email - that's just about all I can think of to stop users from being frustrated when the "email send failed" message keeps coming up.

Thanks for your response, though.

Wizard247

Quote · 2 Mar 2010

http://www.boonex.com/trac/dolphin/ticket/1898

Rules → http://www.boonex.com/terms
Quote · 3 Mar 2010

Thanks, AlexT, but I don't quite understand how that support ticket relates to my problem.


Anyway, I've found a workaround solution as follows:

In tellfriend.php:

Changed
$profileID = 0;
to
(int)$_COOKIE['memberID'] = 0;

Changed
'name' => array(
'type' => 'text',
'name' => 'name',
'caption' => _t("_Your name"),
'value' => $sVisitorName
to
'name' => array(
'type' => 'text',
'name' => 'name',
'caption' => _t("_Your first name"),
'value' => $aVisitorInfo['FirstName']
),
'surname' => array(
'type' => 'text',
'name' => 'surname',
'caption' => _t("_Your surname"),
'value' => $aVisitorInfo['Surname']

This adds a field for surname and changes the "Your name" field to "Your first name".

In order to show both names at the bottom of the "Invite a Friend" email template:

Changed:
$message = str_replace( "<FromName>", $_POST['name'], $message );
to
$message = str_replace( "<FromName>", $_POST['name'] . '&nbsp;' . $_POST['surname'], $message );

In lang-en.php:

Added:
'_Your first name' => 'Your first name',

'_Your surname' => 'Your surname',

Changed:
'_Your email' => 'Your email',
to
'_Your email' => 'Your registered email',

The only "problem" I now have is that the link within the email template only shows the base site URL and does not include "?idFriend=1", although I didn't actually change this part of the php.

Any ideas on that one? Is this suffix required at all?

Apart from that, it all works fantastically!

Regards,
Wizard247

Quote · 3 Mar 2010

Hmmm... cheered too soon...

It seems that only "admin" user is able to successfully send emails via "invite a friend". I just tried to invite a friend under a "standard" login and got the "email send failed" message. Really annoying that this message does not give any further indication as to what is wrong...

Why can standard users not invite friends? Where is this setting? I've checked all possible settings in membership levels and advanced settings, but nothing really refers to being able or not able to invite friends.

Any ideas anyone?

Thanks,
Wizard247

Quote · 3 Mar 2010

Try to apply this changeset: http://www.boonex.com/trac/dolphin/changeset/13743

Rules → http://www.boonex.com/terms
Quote · 4 Mar 2010

Thanks AlexT - that worked up to a point. I completely replaced my old "tellfriend.php" with the new one from the changeset. The fields for login name and email address did indeed fill in automatically. That part worked.

When I get to send it though, I get "email send failed".

However, when I replace the bottom section from "function SendTellFriend()" onwards with the old code from my original tellfriend.php - the email is sent successfully. Below is the code that fails to send from the changeset tellfriend.php:

* send "tell a friend" email
*/

function SendTellFriend() {
global $profileID;

$sRecipient = clear_xss($_POST['friends_emails']);
$sSenderName = clear_xss($_POST['name']);
$sSenderEmail = clear_xss($_POST['email']);
if ( strlen( trim($recipient) ) <= 0 )
return 0;
if ( strlen( trim($sSenderEmail) ) <= 0 )
return 0;

$sLinkAdd = '';
$rEmailTemplate = new BxDolEmailTemplates();
if ( $profileID )
{
$aTemplate = $rEmailTemplate -> getTemplate( 't_TellFriendProfile', $profileID ) ;
$sLinkAdd = 'idFriend='. $profileID;
$Link = getProfileLink($profileID, $sLinkAdd);
}
else
{
$aTemplate = $rEmailTemplate -> getTemplate( 't_TellFriend' ) ;
$Link = BX_DOL_URL_ROOT;
}

$headers .= "From: =?UTF-8?B?" . base64_encode( $sSenderName ) . "?= <{$sSenderEmail}>";
$headers = "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8\r\n" . $headers;
$headers2 .= "-f{$sRecipient}";

$message = $aTemplate['Body'];
$message = str_replace( "<Link>", $Link, $message );
$message = str_replace( "<FromName>", $sSenderName, $message );
return mail( $sRecipient, $aTemplate['Subject'], $message, $headers, $headers2 );
}

?>

Below is the code that does send from original tellfriend.php:

function SendTellFriend() {
global $profileID;

$iVisitorID = (isMember() || isAdmin()) ? (int)$_COOKIE['memberID'] : 0;

if ( strlen( trim($_POST['friends_emails']) ) <= 0 )
return 0;
if ( strlen( trim($_POST['email']) ) <= 0 )
return 0;

$rEmailTemplate = new BxDolEmailTemplates();
if ( $profileID )
{
$aTemplate = $rEmailTemplate -> getTemplate( 't_TellFriendProfile', $profileID ) ;
}
else
{
$aTemplate = $rEmailTemplate -> getTemplate( 't_TellFriend' ) ;
}

$recipient = $_POST['friends_emails'];

$headers .= "From: =?UTF-8?B?" . base64_encode( $_POST['name'] ) . "?= <{$_POST['email']}>";
$headers = "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8\r\n" . $headers;
$headers2 .= "-f{$_POST['email']}";

$sLinkAdd = ($iVisitorID) ? 'idFriend='. $iVisitorID : '';

if ( $profileID )
$Link = getProfileLink($profileID, $sLinkAdd);
else
$Link = BX_DOL_URL_ROOT . ( $sLinkAdd ? "?{$sLinkAdd}" : '' );

$message = $aTemplate['Body'];
$message = str_replace( "<Link>", $Link, $message );
$message = str_replace( "<FromName>", $_POST['name'], $message );

return mail( $recipient, $aTemplate['Subject'], $message, $headers, $headers2 );
}

?>

Because I wanted to show first and last names in the email, I adjusted the script to include those fields in the following areas:


In the page components, replaced the 'name" array with:

'name' => array(
'type' => 'text',
'name' => 'name',
'caption' => _t("_Your first name"),
'value' => $aProfileInfo['FirstName']
),
'surname' => array(
'type' => 'text',
'name' => 'surname',
'caption' => _t("_Your surname"),
'value' => $aProfileInfo['LastName']
),

In the function:  function SendTellFriend():

$message = str_replace( "<FromName>", $_POST['name'] . '&nbsp;' . $_POST['surname'], $message );


OK - almost there. I really appreciate you pointing me in the right direction!

There is one things which I cannot seem to fix:

When I click on "Invite a Friend" - the header goes to "Invite a friend to view the profile" while I wanted the plain Invite A Friend header. Consequently, the wrong email template is used as well inviting the friend to view the Profile instead of the site in general. In the original tellfriend.php, I got the right email template of "Invite a Friend".


Any ideas on how to ensure that the right email template is sent and that the right header is used?

Thanks,
Wizard247

Quote · 5 Mar 2010

This may not have anything to do with the tellfriend.php script itself, but rather my settings in Dolphin 7.0.

Whenever I use "invite a friend" when logged in as "admin", I am able to send the message (with the script as it is currently, even though it sends the wrong email). Whenever I log in as a standard user, I get the "email send failed" message.

I've looked through my settings to try and find something about permissions to send emails, but can't find anything that looks like it needs changing. I am able to send ordinary messages through "compose a message" being logged in as a standard user, so I'm not sure what to look for.

If you could point me in the right direction, I'd appreciate it.

Thanks,

Wizard247

Quote · 6 Mar 2010

I saw improvements to ticket 1898 in change set 13755, but this still sends the wrong email template, "invite to view profile" instead of "invite a friend".

Quote · 7 Mar 2010

Hello wizard247!


Yes, there were some inaccuracies with invitations. Now it was fixed, see changeset 13763-64.

Regard

Quote · 9 Mar 2010

Thanks LeonidS. After incorporating the changeset 13763-64 I was able to adjust this so that the fields "First Name" and "Surname" are shown iso "Nickname" in the form fields (pre-populated) as well as in the email being sent.

Anyone who's interested - here's the full code:

<?php

/***************************************************************************
*                            Dolphin Smart Community Builder
*                              -----------------
*     begin                : Mon Mar 23 2006
*     copyright            : (C) 2006 BoonEx Group
*     website              : http://www.boonex.com/
* This file is part of Dolphin - Smart Community Builder
*
* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
* http://creativecommons.org/licenses/by/3.0/
*
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Creative Commons Attribution 3.0 License for more details.
* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/

require_once('inc/header.inc.php');
require_once(BX_DIRECTORY_PATH_INC . 'design.inc.php');
require_once(BX_DIRECTORY_PATH_INC . 'profiles.inc.php');
require_once(BX_DIRECTORY_PATH_INC . 'utils.inc.php');
require_once(BX_DIRECTORY_PATH_CLASSES . 'BxDolEmailTemplates.php');

bx_import('BxTemplFormView');

// --------------- page variables and login

$_page['name_index']     = 29;
$_page['css_name']        = array('general.css', 'tellfriend.css', 'forms_adv.css');

$_page['header'] = _t("_Tell a friend");
$_page['header_text'] = _t("_Tell a friend");

$profileID = 0;
if( isset($_GET['ID']) ) {
$profileID = (int) $_GET['ID'];
}
else if( isset($_POST['ID']) ) {
$profileID = (int) $_POST['ID'];
}

$iSenderID = getLoggedId();
$aSenderInfo = getProfileInfo($iSenderID);

// --------------- GET/POST actions
$tell_friend_text = '';
if($_POST['submit_send']) {
$tell_friend_text = SendTellFriend($iSenderID) ? MsgBox(_t("_Email was successfully sent")) : MsgBox(_t("_Email sent failed"));
}

// --------------- page components
$sYEmlNotValidC = _t('_Incorrect Email');
$sFEmlNotValidC = $sYEmlNotValidC . ' (' . _t('_Friend email') . ')';

$sCaption = ($profileID) ? _t('_TELLAFRIEND2', $site['title']) : _t('_TELLAFRIEND', $site['title']);

$aForm = array(
'form_attrs' => array(
'id' => 'invite_friend',
'name' => 'invite_friend',
'action' => $_SERVER['PHP_SELF'],
'method' => 'post',
'enctype' => 'multipart/form-data',
'onsubmit' => "var feml = document.forms['invite_friend'].friends_emails; var yeml = document.forms['invite_friend'].email; var bRet = true; if(emailCheck(yeml.value)==false) { alert('{$sYEmlNotValidC}'); bRet = false; } if (emailCheck(feml.value)==false) { alert('{$sFEmlNotValidC}'); bRet = false; } return bRet; "
),
'inputs' => array (
'header1' => array(
'type' => 'block_header',
'caption' => $sCaption,
),
'id' => array(
'type' => 'hidden',
'name' => 'ID',               
'value' => $profileID
),                                   
'name' => array(
'type' => 'text',
'name' => 'name',
'caption' => _t("_Your first name"),
'value' => $aSenderInfo['FirstName']
),
'surname' => array(
'type' => 'text',
'name' => 'surname',
'caption' => _t("_Your surname"),
'value' => $aSenderInfo['LastName']
),
'email' => array(
'type' => 'text',
'name' => 'email',
'caption' => _t("_Your email"),
'value' => $aSenderInfo['Email']
),
'friends_emails' => array(
'type' => 'text',
'name' => 'friends_emails',
'caption' => _t("_Friend email"),
'value' => ''
),           
'submit_send' => array(
'type' => 'submit',
'name' => 'submit_send',
'value' => _t("_Send Letter"),
),               
)
);

$oForm = new BxTemplFormView($aForm);

$_ni = $_page['name_index'];
$_page_cont[$_ni]['page_code'] = $tell_friend_text . $oForm->getCode();
// --------------- [END] page components

PageCode();
// --------------- page components functions

/**
* send "tell a friend" email
*/

function SendTellFriend($iSenderID = 0) {
global $profileID;

$sRecipient   = clear_xss($_POST['friends_emails']);
$sSenderName  = clear_xss($_POST['name'] . '&nbsp;' . $_POST['surname']);
$sSenderEmail = clear_xss($_POST['email']);
if ( strlen( trim($sRecipient) ) <= 0 )
return 0;
if ( strlen( trim($sSenderEmail) ) <= 0 )
return 0;

$sLinkAdd = $iSenderID > 0 ? 'idFriend=' . $iSenderID : '';
$rEmailTemplate = new BxDolEmailTemplates();
if ( $profileID )
{
$aTemplate = $rEmailTemplate -> getTemplate( 't_TellFriendProfile', $profileID ) ;
$Link = getProfileLink($profileID, $sLinkAdd);
}
else
{
$aTemplate = $rEmailTemplate -> getTemplate( 't_TellFriend' ) ;
$Link = BX_DOL_URL_ROOT;
if (strlen($sLinkAdd) > 0)
$sLinkAdd .= '?' . $sLinkAdd;
}
$aPlus = array(
'Link' => $Link,
'FromName' => $sSenderName
);
return sendMail($sRecipient, $aTemplate['Subject'], $aTemplate['Body'], '', $aPlus);
}

?>

Regards,
Wizard247

Quote · 15 Mar 2010
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.