PDA

View Full Version : How to use datamanager to post as Guest ?


memic4
10-11-2011, 11:56 AM
Hi,
How can I insert guest posts from a non-vb page using datamanager? (guest posting is enabled from cp)

At the moment I use the following code (and it works) to add posts to a thread but only for registered users:

.........

// TDM Settings
$tdm =& datamanager_init('Post', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

$tdm->set('userid', $user_id);
$tdm->set('pagetext', $text);
$tdm->set('allowsmilie', 1);
$tdm->set('visible', 1);
$tdm->set('threadid', $thread_id);
$tdm->set('dateline', $date);
$id = $tdm->save();

// rebuild counters
build_thread_counters($thread_id);
build_forum_counters($forum_id);

return $id;


Thanks

kh99
10-11-2011, 04:16 PM
What happens when you try to use it as a guest? Maybe try calling $tdm->pre_save() then check to see if there are any messages in the $tdm->errors array.

memic4
10-11-2011, 10:45 PM
Thanks for the response.
I figured it out.
When you post as guest the user id must be set to 0 and you need to check that the guest username isn't already registered.

$tdm->set('userid', $user_id = 0);
$tdm->set('username', 'Guest Username');