Forum

Thread tagged as: Question, Events, Forms

Build select menu from events app

Hi,

I'm creating a form for people to register a guest list place for an event.

Part of the form has a select menu that I'd like the user to pick an event. How is it possible to list out the event title titles info a drop down menu?

The form is created is a HTML file in the "content" folder and I have included a just to see if an event title loops out but nothing happens.

I couldn't find anything in the solutions section on how you mix up the apps.

<perch:events><perch:events id="eventTitle" /></perch:events>

Thanks

Andrew Cetnarskyj

Andrew Cetnarskyj 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Use perch_events_custom() on the page to output your comma delimited string that the select field needs for its options attribute.

Then you can pass it into the template

$event_options = perch_events_custom(...);
PerchSystem::set_var('events', $event_options);
perch_content_custom(...your form...);

and in your form template:

<perch:input type="select" options="<perch:content id="events" escape="true" />" />

Thanks,

Looked through the custom content documents and having a bit of an issue returning just the titles in a comma delimited string.

My array filters out events in the future and I only want to return eventTitle. However, the code below returns everything in the var_dump

<?php $event_options = perch_events_custom(array(
            array(
                'filter' => 'eventDateTime',
                'match' => 'gte',
                'value' => date('Y-m-d'),
                'sort' => 'eventDateTime',
                'sort-order' => 'ASC',
                ),
            array (
                'skip-template' => true,
                'match' => 'eq',
                'value' => 'eventTitle'
                )
        ));?>

        <?php PerchSystem::set_var('events', $event_options); ?>

    <?php perch_content('Guestlist');?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Something like:

$event_options = perch_events_custom(array(
                'filter' => 'eventDateTime',
                'match' => 'gte',
                'value' => date('Y-m-d'),
                'sort' => 'eventDateTime',
                'sort-order' => 'ASC',
                'skip-template' => true,
        ));
if (count($event_options)) {
 $titles = [];
 foreach($event_options as $opt) {
    $titles[] = $opt['eventTitle'];
  }
  PerchSystem::set_var('events', implode(',', $titles));
}