Pre-Save Helper + Pick Column

0

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?

asked May 28 '10 at 10:31

chris.pilko

889

add comment
enter at least 15 characters

4 Answers

0

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');}
}

answered Jun 8 '10 at 9:18

logikal16

249

add comment
enter at least 15 characters
0

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];

}

answered Jul 18 '10 at 6:31

ihsv

1

add comment
enter at least 15 characters
0

@ihsv - Have you tried using:

$columns['the_state_name']['value'] = $state_names[$id];

answered Jul 18 '10 at 10:59

sc0ttkclark

2936

edited Jul 18 '10 at 11:00

add comment
enter at least 15 characters
0

Perfect! That worked! I can't even begin to thank you enough for that. Btw, awesome plugin!

answered Jul 19 '10 at 6:41

ihsv

1

add comment
enter at least 15 characters