I am using the ElementAPI to generate a json response of data based on the value (locations) that was chosen from a drop-down.
I think I have all of the pieces I need, i'm struggling with how to put them all together I think.
twig
{% set locations = craft.categories.group('locations') %}
...
{% for location in locations %}
<option value="{{ location.slug }}">{{ location.title }}</option>
{% endfor %}
elementapi.php
$slug = craft()->request->getRequiredPost('location'); // chicago
$category = craft()->categories->getGroupByHandle('Locations'); // category group
$location = ??
return [
'endpoints' => [
'myfile.json' => [
'elementType' => 'Entry',
'criteria' => [
'section' => 'mysection',
'relatedTo' => ['targetElement' => $location],
],
'transformer' => function (EntryModel $entry) {
return [
'title' => $entry->title
];
},
]
]
];