Forums | Mahara Community

Open Discussion /
Force to choose category group


anonymous profile picture
Account deleted
Posts: 3

11 June 2013, 19:30

How can I force users to choose a predifined group category when they create a group, in a order to be able to filter groups when someone searches groups ?

Thanks.

anonymous profile picture
Account deleted
Posts: 3

11 June 2013, 21:40

I've found nothing better but modifying the file /mahara/htdocs/group/edit.php, function editgroup_validate(), adding these lines:

if ($group_data->category == 0)
{
        $form->set_error('category', get_string('rule.required.required',  'pieforms', 3));
}
It's a pity to have no other solution but modifying the core source code.

Kristina Hoeppner's profile picture
Posts: 4863

13 June 2013, 21:01

Hello,

There is no way on the interface to force a certain category or to enable forcing to choose a category. Currently, the only way is to customize the core code as you did. You are welcome to submit a patch to the core project to include your solution so you don't have to make customizations in the future. :-)

Cheers

Kristina

 

Aaron Wells's profile picture
Posts: 896

20 June 2013, 19:08

Using the Pieforms API, you could also do it by adding this to the definition for the $elements['category'] form element (around line 359 in group/edit.php):

'rules' => array('required' => true);

That should cause pieforms to do pretty much the same thing as what you've done by adding it manually to the form's validation callback function.

As Kristina suggested, we welcome community contributions. If you'd like to file a bug on Launchpad ( https://bugs.launchpad.net/mahara/+filebug ) and especially if you can provide a code patch that would be suitable for general use, we may be able to add it to the core. Smile

Cheers,
Aaron

anonymous profile picture
Account deleted
Posts: 3

20 June 2013, 21:00

Thanks for the tip.

I'd like to not modify the core.

I'm completely new to mahara so I'd need some time to understand how to write a patch for this soft.

Aaron Wells's profile picture
Posts: 896

21 June 2013, 11:13

No worries. In this case, given that you just want to change the "required" status of one field, I think it might actually make the most sense to modify core.

On the other hand, I suppose if you're not using git for managing your code, it can be hard to keep track of those customizations when you upgrade.

Cheers,
Aaron

6 results