2

I am using the entityform module to capture some user submitted data http://drupal.org/project/entityform

I need to pull in some of the entity field values into one of my templates. I was trying to do this with some code that works for regular node fields..

<?php echo $node->field_title[$node->language]['value']; ?>

I've tried..

<?php echo $entity->field_title[$node->language]['value']; ?>

But that doesn't work. Anyone have any ideas on how I can accomplish this?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Dustin
  • 4,314
  • 12
  • 53
  • 91
  • Should that be field_title[**$entity**->language]['value']; ?> instead? – nmc Oct 09 '12 at 20:59
  • Does this help: http://drupal.stackexchange.com/questions/27293/programmatically-get-field-values – Kev Oct 10 '12 at 23:10
  • I don't think it helps :( Looks like that is just for getting the value of a node's field. I need to get the value of a field from an entity. – Dustin Oct 11 '12 at 16:07

2 Answers2

2
<?php
    $field_data = field_get_items('entityform',$entityform,'field_title');
    echo render(field_view_value('entityform',$entityform,'field_title',$field_data));
?>

field_get_items documentation , field_view_value documentation

mmiles
  • 961
  • 6
  • 9
  • Getting the following error.. Warning: Cannot use a scalar value as an array in include() (line 1 of /home/mrktspac/public_html/nvoy/sites/all/themes/boilerplate/templates/entityform.tpl.php). Fatal error: __clone method called on non-object in /home/mrktspac/public_html/nvoy/modules/field/field.module on line 801 – Dustin Oct 12 '12 at 15:25
  • ok then, your field is not an array, I have updated my code example. You may need to pass your field differently to the field_view_value depending on your field. Or you can echo the raw value from the $field_data array and forget about using field_view_value (but that raw value will not be sanatized) – mmiles Oct 12 '12 at 17:16
  • This is essentially the right answer...a quick look at the module code suggests you should replace `'entity_type'` with `'entityform'` and `$entity` with `$entityform` and that should work – Clive Oct 16 '12 at 17:46
  • @Clive Yeah I was just providing a more general answer, 'entity_type' and $entity are just general variables.Dustin, I have updated my code so it is more specific to the entityform module you are using. – mmiles Oct 19 '12 at 12:54
1

If you know the entityform_id of a submission, you can load it like this:

entity_load('entityform', $entityform_id);
Henry
  • 1,077
  • 1
  • 16
  • 41