I have used createPost() successfully. But, how do I make a reply to the post? Do I also use createPost or do I need to use a different command?
For example, lets say I have a Thread ID. I need to make a reply to a specific thread when I hit a button.
Did you read the function DB ?
http://support.simplemachines.org/function_db/index.php?action=view_function;id=323
it's fairly simple if you don't attach anything.
As butch2k said...it's easy. Look at the available documentation. Here's a hint: look at the id element in $topicOptions.
Thanks, I got it down for the most part. I have a major error though. Here is my code:
<?php
require_once('Sources/Subs-Post.php');
$body = "TestTest";
$msgOptions = array(
'id' => 0,
'subject' => '',
'body' => $body,
);
$topicOptions = array(
'id' => 1310,
'board' => 22,
'mark_as_read' => false,
);
$posterOptions = array(
'id' => 1, //user id Ringmaster_Deadpool
'email' => '',
'name' => '',
);
$test = false;
//Create the Post!
$test = createPost ($msgOptions, $topicOptions, $posterOptions);
?>
It posts 8 of a comment. I have no clue why? Can anyone help with this?
Also, id= 1 is my account. I need a way to get whatever id the user is. I have their screen name saved to a variable already. Any ideas?
global $context;
$posterOptions['name'] = $context['user']['name'];
That should be it, but you'd have to do a print_r(); of $context['user'] to be sure, it's been a while.
The above code still posts the same reply 8 times. What is up with that?
How are you using that file?
The code is not encapsulated in a function, so any time you include the file it is executed.
Duh, I had a serious brain fart. I had it in a loop. Thank you though. I got it to work. Here is the code:
Lainaarequire_once('Sources/Subs-Post.php');
$results = print_r($context['user'], true);
$keywords = preg_split("/[\s,]+/", $results);
$finalID = $keywords[4];
$finalID = (int)$finalID;
$body = "TestTest121";
$msgOptions = array(
'id' => 1310, //Your ID here
'subject' => '',
'body' => $body,
);
$topicOptions = array(
'id' => 1310, //Your ID here
'board' => 22, //Your board here
'mark_as_read' => false,
);
$posterOptions = array(
'id' => $finalID,
'email' => '',
'name' => '',
'update_post_count' => 'always',
);
$test = false;
//Create the Post!
$test = createPost ($msgOptions, $topicOptions, $posterOptions);
The code works great but I'm having trouble calling it. I've spent the entire day trying to learn how to do ajax so I can make this into a homemade quick reply. I know that's not a smf thing though.
I just fixed it! Got an ajax function to work. Although now on my "Forum" homepage, it says
LainaaLatest post by bobdole
in N/A
Does anyone know why?
Does your topic exists ?
'subject' => '',
Give it a subject.