Skip to main content
added 12 characters in body; edited tags; edited title
Source Link
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182

Programmatically How to get fielda list of all the selected values ​for a field programmatically?

How can I get a list of all the selected values ​​for a field?

For example I have a field called countries, and I want to get all countries selected for a certain node.

I need to have this list, because I want the region to be automatically selected in another field (regions), according to the chosen country.

Ex: I choose France in the countries, then automatically the European region is selected in regions

For now I can only copy the selected values ​​in the "countries" field, in the "regions" field, by doing this:

$node->field_regions = $node->field_countries;

Here is the result when I select France in the countries field :

Country: France

Regions: France

Country: France

Regions: France

EditEdit: I tried with the function:field_get_items(), but all I get is an array:

$items = field_get_items('node', $node, 'field_countries', $node->language);

Something is wrong? I also tried with this but I get the same result...

$items = $node->field_countries[$node->language][0]

Programmatically get field values

How can I get a list of all the selected values ​​for a field?

For example I have a field called countries, and I want to get all countries selected for a certain node.

I need to have this list, because I want the region to be automatically selected in another field (regions), according to the chosen country.

Ex: I choose France in the countries, then automatically the European region is selected in regions

For now I can only copy the selected values ​​in the "countries" field, in the "regions" field, by doing this:

$node->field_regions = $node->field_countries;

Here is the result when I select France in the countries field :

Country: France

Regions: France

Edit: I tried with the function:field_get_items(), but all I get is an array:

$items = field_get_items('node', $node, 'field_countries', $node->language);

Something is wrong? I also tried with this but I get the same result...

$items = $node->field_countries[$node->language][0]

How to get a list of all the selected values ​for a field programmatically?

How can I get a list of all the selected values ​​for a field?

For example I have a field called countries, and I want to get all countries selected for a certain node.

I need to have this list, because I want the region to be automatically selected in another field (regions), according to the chosen country.

Ex: I choose France in the countries, then automatically the European region is selected in regions

For now I can only copy the selected values ​​in the "countries" field, in the "regions" field, by doing this:

$node->field_regions = $node->field_countries;

Here is the result when I select France in the countries field :

Country: France

Regions: France

Edit: I tried with the function:field_get_items(), but all I get is an array:

$items = field_get_items('node', $node, 'field_countries', $node->language);

Something is wrong? I also tried with this but I get the same result...

$items = $node->field_countries[$node->language][0]
Tweeted twitter.com/#!/StackDrupal/status/186964023391170560
removed tag from title
Link
Clive
  • 167.9k
  • 19
  • 303
  • 337

Programmatically get field values (Drupal 7)

Source Link
118218
  • 702
  • 3
  • 10
  • 26

Programmatically get field values (Drupal 7)

How can I get a list of all the selected values ​​for a field?

For example I have a field called countries, and I want to get all countries selected for a certain node.

I need to have this list, because I want the region to be automatically selected in another field (regions), according to the chosen country.

Ex: I choose France in the countries, then automatically the European region is selected in regions

For now I can only copy the selected values ​​in the "countries" field, in the "regions" field, by doing this:

$node->field_regions = $node->field_countries;

Here is the result when I select France in the countries field :

Country: France

Regions: France

Edit: I tried with the function:field_get_items(), but all I get is an array:

$items = field_get_items('node', $node, 'field_countries', $node->language);

Something is wrong? I also tried with this but I get the same result...

$items = $node->field_countries[$node->language][0]