Jump to content

Populating drop down with repeater fields values


SIERRA
 Share

Recommended Posts

I have a repeater field called 'class_offerings'. In this I am having the fields class_offering_title, teacher_name and term

I would like to populate a drop down with non empty unique values available in teacher_name. I' m using below code. But this is displaying with duplicates. Could you please suggest on this. Thanks

      <?php 
        $list_teacher=$page->class_offerings->find("teacher_name!='', sort=teacher_name");
        $list_teacher_unique=$list_teacher->unique();
        foreach($list_teacher_unique as $class_teachername) {?>  
              <option value="<?php echo $class_teachername->teacher_name;?>"><?php echo $class_teachername->teacher_name->title;?></option>
        <?php }?>         
 

Link to comment
Share on other sites

I have changed the field type as option and included the needed values. So I can able to populate as below. Now this is working as expected. Thanks

<?php
$get_field = $fields->get('teacher_name');
$field_options = $get_field->type->getOptions($get_field); 

foreach($field_options as $option) {
    echo $option->id;
}
?>

Edited by SIERRA
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...