I have an entityform with a field call "IP" (field_ip is its machine name). Now I need to set a value before that the entityform is saved. I have thinked to use hook_entity_presave() in this way:
function mymodule_entity_presave($entity, $type) {
if ($type == 'entityform') {
if ($entity->is_new === true || 1==1) {
$entity->field_ip = array('LANGUAGE_NONE' => array(0 => array('value' => $_SERVER["REMOTE_ADDR"],'format' => '','safe_value' => $_SERVER["REMOTE_ADDR"])));
$entity->original->field_ip = $entity->field_ip; //Try this, too.
};
}
}
(1==1 is only for test/debug).
Via "devel" module I can see that the new value of field_ip is correctly set, but when I see the new version of the entityform entry (after the save action) I see the default value of that field and not my new value. And infact if I re-edit the same entyform (id) I see the old value and not the new one. Where is my error ?
field_ip
?entityform
. Iffield_ip
is a Text field, you only need to assign its 'value' (text fields do not have 'format' or 'safe_value' properties)