For exapmle when you have: ?country[]=argentina&country[]=uruguay

Is this supposed to work, how?

Comments

hanoii’s picture

I found a possible fix for this on one line, not sure if this might be considered, if so, can provide a patch, is one line though:

function _webform_filter_values() 2649:

$replacement = (!is_array($value) && !is_object($value)) ? $value : '';

for

$replacement = !is_object($value) ? (is_array($value) ? implode($value, ', ') : $value ) : '';

I rather not have a patched version of webforms for now for this as I can come up with alternatives, but any thoughts?

quicksketch’s picture

I don't think this would work for most form elements. Since you'd need the default value to be an actual array for something like checkboxes or a multi-value select list. If you just wanted a comma-separated list you could do ?country=argentina,uruguay in your URL.

hanoii’s picture

Except when I don't control the url, like with views and exposed filters. I am doing a webform that, among other things, captures the exposed filters used of a view. Anyway, I managed to do it by working out something on the submission hook, basically I added something like: %get[xx](multiple) to the token so that I can replace that with a CSV of the arguments. Maybe this only for textfields, but I see there might be little use for this.

quicksketch’s picture

Title: multiple %get[xx] seems not to be working » Support array-format query strings in %get[xx] tokens
Category: bug » feature

I'm changing this into a feature request, since Webform certainly doesn't advertise it's capable of handling array default values and this will require some tricky handling to make it work consistently with single-value and multiple-value fields alike.

m-patate’s picture

Version: 6.x-3.6 » 7.x-3.13

Hi quicksketch,

I've posted some code on the issue "Webform tokens (%session, %post) do not support arrays" that can answer to this request. Could you have a look ?
I think it can answer to the "Add support for user Field module fields e.g. %profile[field_name]"

Thanks

quicksketch’s picture

Title: Support array-format query strings in %get[xx] tokens » Support array-format tokens in [current-page:query:x] tokens
Project: Webform » Token
Version: 7.x-3.13 » 7.x-1.x-dev

I'm sure this is the last thing Dave Reid wants, but due to #1001798: Rewrite token replacement system to use D7 tokens, this problem has now fallen to Token module, which provides [current-page:query:x] tokens (which also don't support arrays currently).

For Webform 3.x, please follow up in #824606: Webform tokens (%session, %post) do not support arrays (though I'm not sure 3.x will ever be fixed with this particular problem).

Dave Reid’s picture

I'm wondering how these tokens would be output in this case? If we can define that then I can begin to support it.

quicksketch’s picture

Dave: I'm guessing that for array-structured GET tokens (like the one in the original post), it would make sense to implode them all together with commas by default and make it possible to implode with other characters if desired, something like [current-page:query:foo:implode:;]. Don't we have a similar syntax somewhere else in Token for imploding lists? I can't remember where I've seen this.

DamienMcKenna’s picture

Issue summary: View changes

Does Token have a standard solution / pattern for accessing specific elements of an array value?

attiks’s picture

#9 AFAIK token has support for array, it introduces a token type 'array' as the following (see token.tokens.inc)

  // Array tokens.
  $info['types']['array'] = array(
    'name' => t('Array'),
    'description' => t('Tokens related to arrays of strings.'),
    'needs-data' => 'array',
  );
  $info['tokens']['array']['first'] = array(
    'name' => t('First'),
    'description' => t('The first element of the array.'),
  );
  $info['tokens']['array']['last'] = array(
    'name' => t('Last'),
    'description' => t('The last element of the array.'),
  );
  $info['tokens']['array']['count'] = array(
    'name' => t('Count'),
    'description' => t('The number of elements in the array.'),
  );
  $info['tokens']['array']['reversed'] = array(
    'name' => t('Reversed'),
    'description' => t('The array reversed.'),
    'type' => 'array',
  );
  $info['tokens']['array']['keys'] = array(
    'name' => t('Keys'),
    'description' => t('The array of keys of the array.'),
    'type' => 'array',
  );
  $info['tokens']['array']['join'] = array(
    'name' => t('Imploded'),
    'description' => t('The values of the array joined together with a custom string in-between each value.'),
    'dynamic' => TRUE,
  );
  $info['tokens']['array']['value'] = array(
    'name' => t('Value'),
    'description' => t('The specific value of the array.'),
    'dynamic' => TRUE,
  );

kkalaskar’s picture

I am facing same problem with
?title=Carpet%20Cleaning&field_geofield_distance[distance]=30&field_geofield_distance[origin]=33314. I want to use 33314 field_geofield_distance[origin] this token but couldn't found any solution to it, so I installed module Custom Tokens. After enabling module /admin/structure/token-custom Create new token with PHP text format


$filter = drupal_get_query_parameters();
$zip_code = $filter['field_geofield_distance']['origin'];
return $zip_code;

Now I get token in Custom

[custom:zip-code]