How to get the values of an array with xPDO?

I’m using formit with a multiple select input field with the name of name="classList[]" so all selected values are passed in an array. Now how can I retrieve those values in my posthook?

$hook->getValue('classList[]'); didn’t work, but that was to be expected, I guess.

I found this older thread with the same question, but unfortunately it never got answered.

Try this:

$classList = $hook->getValue('classList');
$modx->log(modX::LOG_LEVEL_ERROR, 'CLASSLIST: ' . print_r($classList, true));

See what it puts in the error log.

1 Like

I get an array, like expected:

CLASSLIST: Array
(
    [0] => B
    [1] => BE
)

After further investigation, I found that I was using getValues() instead of getValue() (from fetching other inputs) so that’s why it probably didn’t work with the array. Now I can iterate through the values just fine.

Thanks for your help!

I’m glad you got it sorted. :slight_smile:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.