Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8953383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:04:54+00:00 2026-06-15T14:04:54+00:00

I would like to create a forum into a Moodle course (specified by the

  • 0

I would like to create a forum into a Moodle course (specified by the user) using PHP.

I’ve tried to search it for the net but I haven’t found nothing, even in Moodle webservices (in which I cannot find a function to create a forum).

The idea is the user to choose a course (one in which he/she’ll be studying), select a “unit”, insert a title and the content, and submit it (the rest of the options can be the default ones).

I can retrieve all the data I want from Database but I cannot create any forum. I’ve tried adding it via SQL too, but I haven’t been able neither.

Hope someone here can help me!

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:04:55+00:00Added an answer on June 15, 2026 at 2:04 pm

    If you directly want to create a forum then you need to do following steps –

    1. Insert new record into mdl_forum table and get inserted id
    2. Insert new record into mdl_course_module table with following values
      course=courseid,module=7(for forum, in moodle 2.9 the forum id is 9),instance=fourmid,visible=1,showavailability=1
    3. Insert record if not exist or Update record into mdl_course_section with following values and get sectionid
      course = courseid, visible = 1, sequence = moduleid(comma seprated),

    4. Update mdl_course_module table and update sectionid

    Finally rebuild moodle coures cache

    Here is the moodle code to create a new fourm.

    $forum = new stdClass();
    $forum->course = $courseid;
    $forum->type = "general";    
    $forum->timemodified = time();
    $forum->id = $DB->insert_record("forum", $forum);
    
    if (! $module = $DB->get_record("modules", array("name" => "forum"))) {
        echo $OUTPUT->notification("Could not find forum module!!");
        return false;
    }
    $mod = new stdClass();
    $mod->course = $courseid;
    $mod->module = $module->id;
    $mod->instance = $forum->id;
    $mod->section = 0;
    if (! $mod->coursemodule = add_course_module($mod) ) {   // assumes course/lib.php is loaded
        echo $OUTPUT->notification("Could not add a new course module to the course '" . $courseid . "'");
        return false;
    }
    if (! $sectionid = add_mod_to_section($mod) ) {   // assumes course/lib.php is loaded
        echo $OUTPUT->notification("Could not add the new course module to that section");
        return false;
    }
    $DB->set_field("course_modules", "section", $sectionid, array("id" => $mod->coursemodule));
    
    include_once("$CFG->dirroot/course/lib.php");
    rebuild_course_cache($courseid);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create an event signup form using Google Docs. The user
I would like to create a form where a user can enter an arbitrary
I would like to create an order form for my ASP.net page (I included
I would like to create this shape using just css. I am pretty sure
I would like to create a virtual host in apache2, but I want it
ASP.NET newbie here. I would like to create a form with multiple types of
I would like to create a program that will enter a string into the
I would like to create a dynamic form, adding inputs into the form by
I would like to create a form dynamically instead of using the XAML to
I would like to create a test function which change the '.' charachter into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.