tripal_views_form_elements.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Register form elements
  4. */
  5. function tripal_views_elements() {
  6. $type['file_upload_combo'] = array(
  7. '#input' => TRUE,
  8. '#process' => array('expand_file_upload_combo'),
  9. '#element_validate' => array('file_upload_combo_validate'),
  10. );
  11. return $type;
  12. }
  13. /**
  14. *
  15. */
  16. function expand_file_upload_combo ($element, $edit, $form_state, $complete_form) {
  17. if (empty($element['#value'])) {
  18. $element['#value'] = array(
  19. 'items' => '',
  20. 'items_file' => '',
  21. 'file_path' => '',
  22. );
  23. }
  24. //dpm($form_state);
  25. $element['#tree'] = TRUE;
  26. $parents = $element['#parents'];
  27. $parents[] = 'items';
  28. $element['items'] = array(
  29. '#type' => 'textarea',
  30. '#default_value' => $element['#value']['items'],
  31. );
  32. $parents = $element['#parents'];
  33. $parents[] = 'items_file';
  34. $element['items_file'] = array(
  35. '#type' => 'file',
  36. '#title' => 'File upload',
  37. '#default_value' => $element['#value']['items_file'],
  38. );
  39. $parents = $element['#parents'];
  40. $parents[] = 'file_path';
  41. $element['file_path'] = array(
  42. '#type' => 'hidden',
  43. '#default_value' => $element['#value']['file_path'],
  44. );
  45. return $element;
  46. }
  47. /**
  48. *
  49. */
  50. function theme_file_upload_combo($element) {
  51. return theme('form_element', $element, '<div class="container-inline">'. $element['#children'] .'</div>');
  52. }
  53. /**
  54. *
  55. */
  56. function file_upload_combo_validate($element,&$form) {
  57. $file = file_save_upload($element['#name'],array());
  58. if($file) {
  59. $form['values'][$element['#name']]['file_path'] = $file->filepath;
  60. // we need to add our file path to the $_GET element as if it were
  61. // submitted along with the rest of the form
  62. $_GET[$element['#name']]['file_path'] = $file->filepath;
  63. }
  64. }