PDA

View Full Version : Pre-filling the Recipient Box in newpm based on {option} in a bbcode.


ProfC
10-24-2014, 01:58 PM
Hi there,

I am attempting to trouble-shoot a custom bbcode for my forum which would pre-fill the recipient box of the "newpm" page with the userid of the user which featured in the {option} part of the custom bbcode.

The code is designed to use {option} to determine which profile to link to, and it does this, but we seem to have struck an issue in getting it to pre-fill the recipient box in the newpm page.

We appear to need the userid for this, but as I'm not sure on how to get it - it will be different for every user which uses the code. Such as: admin=admin1, admin=admin2 etc

Is there a way to convert the username of a poster (the contents of {option} in this case) to its userid so it'd work with the newpm page?

The specific line of code we're not sure about is this: (We've added the ____ as a placeholder)

<a href="http://www.alexandria-ns.com/private.php?do=newpm&_____"><img src="http://www.alexandria-ns.com/images/misc/message.png" alt="Send a PM?"></a>Any advice would be appreciated.

~ProfC

Full code:
<table cellspacing="0" style="border: solid #003399 1px; border-left: 0; width: 700px; background-color: #FFFFFF;"><tr><td style="width: 190px; border-left: solid #003399 4px; padding: 10px 15px; background-color: #003399; border-right: solid #003399 4px; border-top: solid #003399 1px; border-bottom: solid #003399 1px;" valign="top"> <h1 style="margin: 0; padding: 0;font-size: 11pt; font-weight: normal;"><a href="http://www.alexandria-ns.com/member.php?do=getinfo&amp;username={option}" target="_blank" onclick="javascript<b></b>:window.open(this.href, 'Profile of: {option}, 'width=800,height=400,resizable=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes'); return false;" style="color: #e3dc0b;"><b>{option}</b></a></h1><p style="margin: 0; padding: 0;color: #e3dc0b; font-size: 8pt; padding: 3px 0;">Administrator's Comment</p><div style="margin-top: 10px;"></div><br><a href="http://www.alexandria-ns.com/private.php?do=newpm&_____"><img src="http://www.alexandria-ns.com/images/misc/message.png" alt="Send a PM?"></a> </td><td style="width: 440px; padding: 10px 15px; font-size: 8pt; border-right: solid #003399 4px; border-top: solid #003399 1px; border-bottom: solid #003399 1px;" valign="top"><b>{param}</b></td></tr></table>

kh99
10-24-2014, 02:38 PM
I think member.php takes either &username=... or &userid=..., so maybe that would solve the problem.

ProfC
10-24-2014, 02:59 PM
I think member.php takes either &username=... or &userid=..., so maybe that would solve the problem.

I've tried that, but when we use "&username={option}" it just takes us to a new message without the recipient box containing the user in question.

As for "&userid=" I'm currently lost on how to link it to the username given in {option}. As vBulletin appears to use the userid to define the recipient when you click "Send PM" from their profile.

Screenshot: http://gyazo.com/322334da18a8c5cc915e5d6200c705a2 (Sorry for not posting one in sooner)

kh99
10-24-2014, 03:26 PM
I guess I was thinking that you could change the bbcode to take userid as the option, then use that in the profile link, but I guess you don't want to do that (I guess if a user is entering it then they don't want to have to look up the userid).

So what you could do is create a plugin using hook location private_newpm_blank and code like this:

$vbulletin->input->clean_gpc('r', 'username', TYPE_STRING);
if ($vbulletin->GPC['username'] != '')
{
// validate username
if ($user = $db->query_first_slave("SELECT userid FROM " . TABLE_PREFIX . "user WHERE username = '" . $db->escape_string($vbulletin->GPC['username']) . "'"))
{
if (empty($pm['recipients']))
$pm['recipients']= $vbulletin->GPC['username'];
else
$pm['recipients'] .= ' ; '.$vbulletin->GPC['username'];
}
}



I haven't tested it but it looks like it should work.

ProfC
10-24-2014, 03:34 PM
That works perfectly, thank you so much.

CoffeeLovesYou
10-24-2014, 03:40 PM
If I understand your question, this already exists in vB.

http://www.website.com/forums/private.php?do=newpm&u[]=1&u[]=2&u[]=3&u[]=4&u[]=5

ProfC
10-24-2014, 03:46 PM
If I understand your question, this already exists in vB.

http://www.website.com/forums/private.php?do=newpm&u[]=1&u[]=2&u[]=3&u[]=4&u[]=5

Thank you for your reply, the problem I was facing was trying to get the recipient name to autofill with the name displayed in:

http://gyazo.com/322334da18a8c5cc915e5d6200c705a2

The plugin code given to me by kh99 has sorted the matter and made me kick myself for not posting sooner. Much simpler and more straightforward than any option I've been looking at.