How to access field values from an entity reference field in a custom module? I'm making a custom payment module for Commerce that references a Credit Card entity. I have the entity reference form field in there and working but I cannot pass on the selected Credit Card entity to the "message" field. If I could just print whatever the title of the entity reference they select, that would work, or if I could access one of the 5 fields in the entity itself, that would be ideal.

Here is my module: http://pastebin.com/373WDAzA and this is the error message I get:


  Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1559 of C:\xampp\htdocs\includes\bootstrap.inc).
$form['card_on_file' ] = array(
  '#type' =&gt; 'entityreference',
  '#title' =&gt; t ('Credit Card'),
  '#era_entity_type' =&gt; 'node', // Mandatory 
  '#era_bundles' =&gt; array(credit_card ), // Optional (Any bundle by default).
  '#era_cardinality' =&gt; 5, // Optional (1 By default).
  '#required' =&gt; TRUE,
) ;


the warning corresponds to this replace this code:

'#era_bundles' =&gt; array(credit_card ), // Optional (Any bundle by default).


with

'#era_bundles' =&gt; array('credit_card'),


Link: https://api.drupal.org/api/drupal/includes!common.inc/function/entity_load/7

$ids = array();


get $ids from $form_state['values'] of submit handler function.

use entity_load('credit_card', $ids);