## General developer forum

This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.

Hello,

I need a way to add a new post to a discussion forum by php code ... I tried forum_add_new_post function

but I couldn't use it well .. is there anyone that used this function before? or have another way to do the target?

Average of ratings: -
What was the problem you faced? Did you get an error message? Did you have debug set to developer level?

Average of ratings: -

Thanks a lot Mr. Dan I solved the problem  (it was with the $post object that I created in the code) However.. do you know how I can get the url of profile picture for a particular user from moodle? I need to display the user picture in my application I found "user_picture" function which display the user image only .. I need the url !!! or even the picture file name Average of ratings: - Re: add new post Its complicated You should be able to do it by creating an instance of the user_picture class and calling get_url(). (Look at that class in lib/outputcomponents.php). (Edit: I see you've asked in another thread). Average of ratings: Useful (1) Re: add new post Hello,, I'm sorry I used the following function from moodle : forum_add_new_post($post, null, $message); to add new post for a new discussion forum I generated the following object called$post in order to get the information that are needed

$post = new stdClass();$post->course         = "5";
$post->forum = "2";$post->discussion    = "19";
$post->parent = "19";$post->d_subject     = "a new test";
$post->subject = 'Re: '.$post->d_subject;
$post->message = 'Test .. Add new post';$post->messageformat = 1;
$post->messagetrust = 0;$post->groupid = -1;
\$post->itemid  = 0;

in the beginning I didn't have any problem with this .. but today when I tried to rewrite it I found the error in the attached image.

all my old file has been deleted by mistake from one week only ... I collected my codes again but I have problem with this ... I didn't remember how I solved its problem

there's something missing here, maybe the post object is not correct, right?

waiting you ... the time will finish soon

Average of ratings: -