Input Helpers: how to output PICK columns from POD?

0

I have 3 PODs:

country ---(1 to many)---> region ----(1 to many)---> location

When adding a location, I want the user to pick a region. This is fine as the core PODs functionality allows for this very easily. The problem I'm having is how to output the country name in the dropdown as well (see screenshots below).

My region POD is setup as follows:

alt text

But when I output $val in the helper, the array only contains:

Array( [id] => 7 [name] => Central Highlands [body] => [slug] => central-highlands [active] => )

So as you can see, it's missing "country" and "location". Is there any way to reference these items through the helper? To give you an idea of what I'm trying to do, see the screenshots below:

What I currently have as an output is this:

alt text

======

What I want is this: alt text

Any help you can give would be greatly appreciated!

asked Jul 1 '10 at 8:05

scottybowl

50

edited Jul 1 '10 at 8:06

add comment
enter at least 15 characters

2 Answers

1

Yes, that is the easiest way to achieve this kind of PICK menu. I did a similar thing in a location package I made: http://podscms.org/packages/pod-locations/. I used a sorting callback to pre-sort the array of regions by states and then used <optgroup> tags to separate the regions by state in the menu.

This does make many more DB queries than necessary (2 per get_field), but until you have a lot of entries, you probably won't see much performance lag because the queries in Pods are pretty well optimized. Pods::findRecords does accept a fourth parameter to override the normal sql query with your own, and you could probably get all the data you need in one query. It would be a pretty advanced and complex query though, and I wouldn't want to try and tackle it unless absolutely necessary.

answered Jul 1 '10 at 2:13

clarinetlord

456

edited Jul 1 '10 at 2:14

add comment
enter at least 15 characters
0

Update: I've done this but it seems very resource intensive:

<select id="<?php echo $css_id; ?>" class="form pick1 <?php echo $name; ?> pods_field pods_field_<?php echo $name; ?> pods_coltype_pick">

<option value="">-- Select One --</option> <?php if ( !empty( $value ) ) : ?> <?php foreach ($value as $key => $val) : ?>

  <?php
    // check to see if this is the chosen value
    $selected = empty($val['active']) ? '' : 'selected';
    $Record = new Pod("region");
    $Record->findRecords('t.name ASC',1,'slug="'.$val['slug'].'"');
    while ($Record->fetchRecord()) {
        $val['name'] = $Record->get_field('country.name').': '.$val['name'];   
    }
    ?> 

  <option value="<?php echo $val['id']; ?>"<?php echo $selected; ?>><?php echo $val['name']; ?></option>
<?php endforeach ?>

<?php endif ?> </select>

answered Jul 1 '10 at 8:26

scottybowl

50

add comment
enter at least 15 characters