function custom_changes_civicrm_buildForm($formName, &$form) {
if ($formName == 'CRM_Member_Form_Membership'){
  foreach($form->_elements as $key => $value){
    if ($key == 4){
    $assoc_array =  $value->_options[1][67];
     $form->_elements[$key]->_options[1][67] = $assoc_array;

I want to alter the options order by using ksort, but I dont find any function to alter the elements like setLabel which sets label

Which is the function for altering and changing options in an element?

  • 1
    Why these options would be displayed in alpha order rather than in the order set in Membership Types is beyond me. I'd class that as a bug. What's the point in being able to order them if that order is not followed when displayed on a sign-up/renewal form? – Graham Feb 18 '17 at 17:49

I'd do it like this:

  1. First get the name of the select element, and then get the elemement using this

$element =& $form->getElement('name-of-select-element');

i.e. don't hard code that 4.

  1. You've got the options array correct, i.e. $element->_options

Now you can just replace that options like you're doing, but depending on the widget in use it can be confusing how it's structured. The one I was working on recently has option['text'] as the label. Sorting by array values can be done manually or cleverly with some php and callback functions if you're ambitious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.