Advertisement
Guest User

Untitled

a guest
Jun 17th, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.22 KB | None | 0 0
  1. <?php
  2.  
  3. function farm_quick_machinery_form($form, &$form_state){
  4.   $form['quick_machinery'] = array(
  5.     '#type'=>'fieldset',
  6.     '#title' => t('Record machinery logs'),
  7.     '#description' => t('Use this form to record machinery logs against equipment'),
  8.   );
  9.  
  10.  
  11.   $form['quick_machinery']['title'] = array(
  12.     '#type' => 'textfield',
  13.     '#title' => t('Log Name'),
  14.     '#description' => t('The name of the log'),
  15.     '#required' => TRUE,
  16.  
  17.   );
  18.  
  19.   $form['quick_machinery']['timestamp'] = array(
  20.   '#type' => 'date_select',
  21.   '#title' => t('Date'),
  22.   '#date_format' => 'M j Y H:i',
  23.   '#date_type' => DATE_FORMAT_UNIX,
  24.   '#date_year_range' => '-10:+3',
  25.   '#default_value' => REQUEST_TIME,
  26.   '#required' => TRUE,
  27.   );
  28.  
  29. $form['quick_machinery']['asset'] = array(
  30. '#type'=>'textfield',
  31. '#title' => t('Equipment'),
  32. '#description' => t('Select the equipment the log is for'),
  33. '#autocomplete_path' => 'farm_asset/autocomplete/equipment',
  34.  
  35.   );
  36.   $form['quick_machinery']['area']['name'] = array(
  37.     '#type' => 'textfield',
  38.     '#title' => t('Work Area'),
  39.     '#description' => t('Enter the name of the area you worked in, and select it from the list that drops down'),
  40.     '#autocomplete_path' => 'taxonomy/autocomplete/field_farm_area',
  41.     '#required' => TRUE,
  42.   );
  43.  
  44.  
  45.   $form['quick_machinery']['description'] = array(
  46.     '#type' => 'text_format',
  47.     '#title' => t('Notes'),
  48.     '#format' => 'farm_format',
  49.     '#description' => t('Suggested things to record in the notes: <ul><li>Usage - Where it was used, what you did</li><li>Refuelled or oiled?</li><li>if any parts have been replaced</li></ul>'),
  50.   );
  51.  
  52.   $form['quick_machinery']['hours'] = array(
  53.     '#type' => 'textfield',
  54.     '#title' => t('Hours on the clock'),
  55.     '#description' => t('Hours on the hour meter on the machine, or the amount of time used for'),
  56.     '#element_validate' => array('element_validate_number'),
  57.  
  58.   );
  59.   $form['quick_machinery']['faultcheck'] = array(
  60.     '#type'=> 'select',
  61.     '#title' => t('Faults found?'),
  62.     '#description' => t('Any issues identified with the machine? If yes, please list them below'),
  63.     '#options' => array(0 => t('No'), 1 => t('Yes')),
  64.     '#default_value'=>0,
  65.     '#ajax'=>array(
  66.      'callback'=>'farm_quick_machinery_quick_form_faults_ajax',
  67.      'wrapper'=>'machinery-faults'
  68.     ),
  69.   );
  70.  
  71.  
  72.   $form['quick_machinery']['fault'] = array(
  73.     '#type'=>'container',
  74.     '#prefix' => "<div id='machinery-faults'>Logs here",
  75.     '#suffix'=>'</div>',
  76.   );
  77.  
  78. $checkbox = !empty($form_state['values']['faultcheck']) ? $form_state['values']['faultcheck'] : 0;
  79. if ($checkbox == 1){
  80.     $form['quick_machinery']['fault']['faultform'] = array(
  81.       '#type' => 'fieldset',
  82.       '#title' => t('Fault reporting'),
  83.       '#description' => t('Report any faults with equipment here'),
  84.     );
  85.     $form['quick_machinery']['fault']['faultform']['description'] = array(
  86.       '#type'=>'textfield',
  87.       '#title'=>'Fault details',
  88.       '#description'=>t('Please enter details of the fault, including where it happened and how it happened.')
  89.     );
  90.   };
  91.  
  92.  
  93.  
  94.  
  95.   return $form;
  96. }
  97.  
  98. function farm_quick_machinery_quick_form_faults_ajax($form, &$form_state){
  99.  
  100.   return $form['quick_machinery']['fault'];
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement