Automatically create BuddyPress group after creating the category

Hello, there

As title says. I guess there's no plugin for that, so I began to dig in the code. I'm not familiar with it, so I can only do it the hard way.

I guess I will need groups_create_group function found in bp-groups-functions.php for that. I works pretty well, but it is executed everytime I refresh the page and that's one problem. The other is I don't know yet, how to access the variables passed in the form to the function.

Any help?