🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!
Guides & Tutorials October 27, 2026

How to Enrol Users into Moodle Courses from Gravity Forms

GravityExtra
How to Enrol Users into Moodle Courses from Gravity Forms

Running a course on Moodle is one job; getting people into it is another. Every new intake brings the same small chores: take the sign-ups, check who already has an account, create the ones who do not, and enrol each person into the right course with the right role. Done by hand it is slow and easy to get wrong, and a student who is left un-enrolled is a student who cannot start. This guide shows how to connect a Gravity Forms sign-up form to your own Moodle so the whole thing happens on its own, the moment the form is submitted, with the Gravity Forms Moodle Premium Add-on and without writing a line of code.

What the add-on does

The idea is simple. A visitor fills in a Gravity Forms form — a course sign-up, a membership application, a paid checkout. When they submit it, the add-on looks the person up in your Moodle by their email address. If they already have an account, it enrols that account into the course and role you picked. If they do not, and you have asked it to, the add-on creates the Moodle account first and then enrols it. From the visitor’s point of view they filled in a form; behind the scenes they are now a student in your course.

All of this runs through your own Moodle, over its Web Services interface, with a token you create and control. The request travels straight from your WordPress server to your Moodle site. Nothing goes through a third party, and your token is encrypted on your site so it is never left in the open.

Why Moodle Web Services, and not a plugin on the Moodle side

Moodle is its own application, often on its own server, sometimes hosted by someone else entirely. You cannot reach into it with a WordPress function the way you would an LMS plugin that lives inside WordPress. What Moodle gives you instead is a proper, supported door: Web Services. Turn them on, enable the REST protocol, and Moodle exposes a set of named functions — create a user, find a user, enrol a user — that an outside system can call with a token. That is exactly what this add-on uses. It is the official way in, which means it keeps working across Moodle upgrades and does not depend on anything unofficial.

Step 1: switch on Web Services in Moodle

The first steps are in Moodle, as an administrator. Open Site administration → Advanced features and tick Enable web services. Then open Site administration → Server → Web services → Manage protocols and enable the REST protocol. Those two switches are what let an outside system talk to Moodle at all; without them, every call is refused.

Step 2: choose the functions and make a token

A Moodle token belongs to a service, and the service lists the functions the token is allowed to use. Create a service (or use the built-in one) and add the functions this add-on needs: core_webservice_get_site_info for the connection test, core_user_get_users_by_field to find a user by email, core_enrol_manual_enrol_users to enrol, and — only if you want accounts created automatically — core_user_create_users. Then, under Manage tokens, create a token for a Moodle user who is allowed to enrol people and, if needed, create users. Copy the token and keep it safe; it is as powerful as that user’s login.

One extra point about enrolment: Moodle’s manual enrolment call only works on courses where the Manual enrolments method is enabled. It is on by default for most courses, but if an enrolment is refused, that is the first thing to check.

Step 3: connect WordPress to Moodle

Back in WordPress, install and activate the add-on after Gravity Forms, then open Forms → Settings → Moodle. Put your Moodle’s web address into the Moodle site URL field — just the site root, like https://learn.yourschool.com; the add-on adds the /webservice/rest/server.php part itself. Paste the token into the Web Services token field. The token is stored encrypted and is shown blank afterwards, so nobody reading the settings page can see it.

The settings page runs a quick connection test. When the site URL and token are right, it shows your Moodle site name and version in green, which is your proof that the two systems can talk. If something is off, it tells you what: a wrong token, a site URL that is not the Moodle root, or web services that are not switched on.

Step 4: add a feed to your form

Open the form you use for sign-ups, go to its Moodle settings, and add a feed. Set the Course ID (the number in the course’s view.php?id=NN address) and the Role ID (5 is Student on a default Moodle). Map your form’s email field to the required email, and optionally map a first name, last name and username. Decide whether the add-on should create the account when the email is new, and whether Moodle should send its own welcome email with a fresh password or the add-on should set a strong random one. Add conditional logic if you want the feed to run only for certain answers — a chosen course, a paid order — and you can add several feeds for several courses on the one form.

The full walk-through of every setting, with screenshots, is in the Gravity Forms Moodle setup guide.

What happens on submit

When a form is submitted and the feed’s conditions are met, the add-on asks Moodle whether a user has that email. If one does, it enrols that user into the course and role. If none does and account creation is on, it creates the account and then enrols it. A note goes on the Gravity Forms entry either way, recording whether the account was created or already existed, which course and role were used, or exactly why it failed. The email in the note is masked, so the full address is not stored in your records.

Crucially, the enrolment runs after the entry is saved, on your server. A slow or failing Moodle never blocks the visitor: they always get their confirmation, and you get a clear note to act on. Nothing is retried silently, so you are never guessing about what went through.

Keeping the token safe

The token is the key to your Moodle, so the add-on treats it like one. It is encrypted with AES-256-GCM before it is stored, using key material from your site’s own secret salts, so a stolen database alone cannot read it. It is sent to Moodle only in the body of each request, never in the URL, so it does not end up in a server log. It is never shown again after you save it, never written onto an entry, and never put into a note. And the add-on only ever contacts the one Moodle address you configured.

Frequently asked questions

Do I need to install anything inside Moodle?

No plugin. You only turn on Web Services and the REST protocol, pick the handful of functions, and create a token — all built into Moodle. There is nothing to install on the Moodle side and nothing to maintain there beyond the token.

Which Moodle functions does the token need?

Four: core_webservice_get_site_info for the connection test, core_user_get_users_by_field to find the user by email, core_enrol_manual_enrol_users to enrol, and core_user_create_users if you want accounts created automatically. Leave the last one out of the service and the add-on simply enrols people who already have an account.

What if the person does not have a Moodle account yet?

You choose. With account creation off, a submission from someone without an account is noted and skipped, so only existing members are enrolled. With it on, the add-on creates the account with the mapped name and username, then enrols it. You also choose whether Moodle emails the new person a welcome message with a password, or the add-on sets a strong random password they reset themselves.

How do I find the course id and role id?

Open the course in Moodle and read the id from the address bar — it is the number in course/view.php?id=NN. For roles, open Site administration → Users → Permissions → Define roles; on a default site the Student role is 5. Both fields take a positive whole number, and the add-on checks the value before it saves.

Is the token kept private?

Yes. It is encrypted at rest, sent only in the request body, never shown again after saving, and never written to an entry, a note or a log. The add-on contacts only the Moodle site you configured, server to server, so the visitor’s browser never sees the token or touches Moodle.

What happens if Moodle is down when a form is submitted?

The submission still goes through. The enrolment runs after the entry is saved, and if the call fails, the entry gets a note explaining why; the visitor is never held up or turned away. You can re-run the feed from the entry once Moodle is back.

Set it up once, then forget it

The work is all in the setup: two switches and a token in Moodle, a site URL and that token in WordPress, and a feed on your form. After that, every matching sign-up becomes a Moodle enrolment on its own, with a clear record on each entry. Ready to connect your forms to your courses? Get the Gravity Forms Moodle Premium Add-on and turn sign-ups into enrolments automatically.

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr