function farm_livestock_weight_asset_form_submit in farmOS 7
Submit handler for processing the animal weight field.
Parameters
array $form: The form array.
array $form_state: The form state array.
1 string reference to 'farm_livestock_weight_asset_form_submit'
- farm_livestock_weight_form_farm_asset_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 944 - Farm livestock weight module.
Code
function farm_livestock_weight_asset_form_submit(array $form, array &$form_state) {
// Only proceed if weight has a value.
if (empty($form_state['values']['weight']['value'])) {
return;
}
// Only proceed if the value is not the default value.
if ($form_state['values']['weight']['value'] == $form['weight']['value']['#default_value']) {
return;
}
// If an asset doesn't exist, bail.
if (empty($form_state['values']['farm_asset'])) {
return;
}
// Grab the asset, weight, and units.
$asset = $form_state['values']['farm_asset'];
$weight = $form_state['values']['weight']['value'];
$units = $form_state['values']['weight']['units'];
// Create an observation log to set the weight.
farm_livestock_weight_set($asset, $weight, $units);
}