In my entityform, different fields appear based on choices (dependencies). Two appear at once. I'm multiplying the values using a Computed field. All works if the variables have a value. I have 8 fields I want to multiply, but ignore the empty values. Can't set field defaults to 0 (wrecks multiplication) or 1 (messes with totals).
The following Warningwarning appears for each empty field -field; here it's "line 1" for the 1st variable/field. No warning for those that have a value: Warning: array_pop() expects parameter 1 to be array, null given in eval() (line 1 of /home/content/67/10793667/html/sites/all/modules/computed_field/computed_field.module(466) : eval()'d code).
Warning: array_pop() expects parameter 1 to be array, null given in eval() (line 1 of /home/content/67/10793667/html/sites/all/modules/computed_field/computed_field.module(466) : eval()'d code).
Tried many different null and empty PHP codes, nothing works - sure it's my error - not a pro. How can I instruct the computed field to ignore the empty fields?
Here is my Computed Code (PHP) $howmany = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_how_many'))); $price1 = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_reg_price1'))); $price2 = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2'))); $entity_field[0]['value'] = $howmany*$price1*$price2;.
$howmany = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_how_many')));
$price1 = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_reg_price1')));
$price2 = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2')));
$entity_field[0]['value'] = $howmany*$price1*$price2;
I tried adding this after the $price2$price2
line, but it didn't work.
if ($price2 == null) {
$price2 = 1;
}
if ($price2 == null) {
$price2 = 1;
}
Tried If else alsoI tried this too, and it didn't work:
if (!empty($price2)) { $price2 = 1; } else { $price2 = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2'))); }.
Many Thanks Daniel
if (!empty($price2)) {
$price2 = 1;
}
else {
$price2 = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_sale_price2')));
}