Advertisement:

createPost() Help? How do I make a reply?

Aloittaja bobdole2281, elokuu 07, 2013, 02:13:38 IP

« edellinen - seuraava »

bobdole2281

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.

butch2k


Matthew K.

As butch2k said...it's easy. Look at the available documentation. Here's a hint: look at the id element in $topicOptions.

bobdole2281

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?

bobdole2281

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?

Matthew K.

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.

bobdole2281

The above code still posts the same reply 8 times. What is up with that?

emanuele

How are you using that file?
The code is not encapsulated in a function, so any time you include the file it is executed.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

bobdole2281

#8
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.

bobdole2281

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?

butch2k


emanuele



Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Advertisement: