You are here

function farm_livestock_weight_form_farm_livestock_birth_form_submit in farmOS 7

Submit function for livestock birth form to set child birth weights.

1 string reference to 'farm_livestock_weight_form_farm_livestock_birth_form_submit'
farm_livestock_weight_form_farm_livestock_birth_form_alter in modules/farm/farm_livestock/farm_livestock_weight/farm_livestock_weight.module
Implements hook_form_FORM_ID_alter().

File

modules/farm/farm_livestock/farm_livestock_weight/farm_livestock_weight.module, line 1001
Farm livestock weight module.

Code

function farm_livestock_weight_form_farm_livestock_birth_form_submit($form, &$form_state) {

  // Iterate through child animal assets that were created during form
  // submission and create weight measurement logs..
  if (!empty($form_state['storage']['children'])) {
    foreach ($form_state['storage']['children'] as $delta => $child_asset) {
      if (!empty($form_state['values']['birth']['child'][$delta]['weight'])) {
        $weight = $form_state['values']['birth']['child'][$delta]['weight'];
        $units = $form_state['values']['birth']['child'][$delta]['units'];
        $timestamp = strtotime($form_state['values']['birth']['timestamp']);
        farm_livestock_weight_set($child_asset, $weight, $units, $timestamp);
      }
    }
  }
}