Pre-Save Helper + Pick Column
I've been playing with the Google Geocoding pre-save helper written by gr0b1. I'm trying to add information from my state and country columns in my pod. Both of these are Pick columns.
I can get to the ID of the columns using $column['state']['value']. Is there a way to traverse this and get to the name?
4 Answers
For PICK columns, that variable doesn't contain anything but IDs, so there's nothing to traverse.
You'll need to do a lookup using the ID(s).
<?php
$state_names = array();
$ids = $columns['state']['value'];
// Make sure it's an array so we can loop through it
$ids = is_array($ids) ? $ids : array($ids);
foreach ($ids as $id) {
$Record = new Pod('state', $id);
$state_names[$id] = $Record->get_field('name');}
}
I'm trying to do something similar here with a pre-save helper. What I'd like to do is populate a text field with the pick column "state". The problem is that it's consistently outputting just the first letter of the state. It seems that no matter what I try I can't get past this one issue. Has anyone else had this problem?
The code I'm using is as follows:
$state_names = array();
$ids = $columns['state']['value'];
$ids = is_array($ids) ? $ids : array($ids);
foreach ($ids as $id) {
$Record = new Pod('state', $id);
$state_names[$id] = $Record->get_field('name');
$columns['the_state_name'] = $state_names[$id];
}
@ihsv - Have you tried using:
$columns['the_state_name']['value'] = $state_names[$id];
edited Jul 18 '10 at 11:00
Perfect! That worked! I can't even begin to thank you enough for that. Btw, awesome plugin!


