Limit form submission to a certain number

We have a lot of training courses with a limited number of participants. It is really annoying to keep track of the number manually, especially there are different workflows which depend on the number!