How to set form select element options in page?

I am doing registration for events by this example https://getkirby.com/docs/cookbook/forms/creating-pages-from-frontend

It will be registration for tennis tournaments. For each event form should be the same, but only there should be different groups. For example, all available groups are A, B, C, D, E, F, G, H, and for one event there should be only A, D, G groups, and for another event there should be only C, D, E groups. The point is to show only those groups, that are valid for each event. I will have all groups in event.yml as checkboxes field, so that editor can select groups for each event.

Question is, how to show these selected values in registration form?

Fetch the options into an array and then render the options in your select field, something like this:

<?php
$options = $page->groups()->split(',');
?>
<label for="groups">Choose a group</label>
<select name="groups">
 <option value="">--Please choose an option--</option>
  <?php foreach ($options as $option): ?>
  <option value="<?= $option ?>"><?= $option ?></option>
  <?php endforeach ?>
</select>

Works perfect, thank you very much for help!

Oh, only one more thing, it is saving machine name, how can I change it to human / field value?

machine-name

Changed event.yml blueprint to this:

sections:
  content:
    type: fields

<…>

      group:
        width: 1/2
        label: Grupės
        type: checkboxes
        options:
          - First group (value)
          - Second group (value)
          - Third group (value)
          - Fourth group (value)

So now gruops are saved as value (not as machine name). Only not sure if it’s the best solution, I mean maybe would still need machine names in future.

I’d use machine names and vote for one of the other options described in that recipe…