You are here

function farm_livestock_milk_form in farmOS 7

Form for adding milk harvest logs.

2 string references to 'farm_livestock_milk_form'
farm_livestock_farm_quick_forms in modules/farm/farm_livestock/farm_livestock.farm_quick.inc
Implements hook_farm_quick_forms().
farm_livestock_milk_form_submit in modules/farm/farm_livestock/farm_livestock.farm_quick.milk.inc
Submit function for milk quick form.

File

modules/farm/farm_livestock/farm_livestock.farm_quick.milk.inc, line 10
Farm livestock milk quick form.

Code

function farm_livestock_milk_form($form, &$form_state) {

  // Determine the default quantity measure and units based on the system of
  // measurement (Weight in Lbs for US/Imperial, Volume in Liters for Metric).
  $system = farm_quantity_system_of_measurement();
  $default_measure = 'volume';
  $default_units = 'liters';
  if ($system == 'us') {
    $default_measure = 'weight';
    $default_units = 'lbs';
  }

  // We also remember what the measure and units were from the previous
  // submission. So if those are set, override the defaults.
  $default_measure = variable_get('farm_livestock_milk_measure', $default_measure);
  $default_units = variable_get('farm_livestock_milk_units', $default_units);

  // Wrapper fieldset.
  $form['milk'] = array(
    '#type' => 'fieldset',
    '#title' => t('Record a milk harvest'),
    '#description' => t('Use this form to record a milk harvest. A harvest log will be created with standard details filled in.'),
  );

  // Animal/group select.
  $form['milk']['asset'] = array(
    '#type' => 'textfield',
    '#title' => t('Group/animal'),
    '#description' => t('Select the group/animal that this milk came from.'),
    '#autocomplete_path' => 'farm_asset/autocomplete/animal+group',
    '#required' => TRUE,
  );

  // Quantity measure.
  $form['milk']['measure'] = array(
    '#type' => 'select',
    '#title' => t('Measure'),
    '#description' => t('Is this harvest measured in weight or in volume?'),
    '#options' => array(
      'weight' => t('Weight'),
      'volume' => t('Volume'),
    ),
    '#default_value' => $default_measure,
    '#required' => TRUE,
  );

  // Quantity value.
  $form['milk']['quantity'] = array(
    '#type' => 'textfield',
    '#title' => t('Quantity'),
    '#required' => TRUE,
    '#element_validate' => array(
      'element_validate_number',
    ),
  );

  // Quantity units.
  $form['milk']['units'] = array(
    '#type' => 'textfield',
    '#title' => t('Unit of measure'),
    '#description' => t('Specify what units this harvest is measured in. This will remember what you entered previously, so if you use standard units you only need to enter them the first time you use this form.'),
    '#autocomplete_path' => 'taxonomy/autocomplete/field_farm_quantity_units',
    '#default_value' => $default_units,
    '#required' => TRUE,
  );

  // Submit button.
  $form['milk']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save log'),
  );

  // Return the form.
  return $form;
}