Advertisement
Ashlar

Drupal Form to Select a file.

Dec 15th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function crhubTestForm() {
  2.   return drupal_get_form('crhub_crhubTestForm');
  3. }
  4.  
  5. function crhub_crhubTestForm($form_state) {
  6.    
  7.   $form['upload_file'] = array(
  8.     '#type' => 'file',
  9.     '#title' => t('File to read')
  10.   );
  11.  
  12.     //SUBMIT BUTTON
  13.   $form['submit'] = array(
  14.     '#type' => 'submit',
  15.     '#value' =>'Submit',
  16.   );
  17.   return $form;
  18. }
  19. function crhub_crhubTestForm_validate($form, &$form_state) {
  20.   $filePath = $form_state['values']['upload_file'];
  21.   dsm($form_state['values']);
  22.   if ($filePath) {
  23.        if (is_file($filePath)){
  24.          form_set_error('upload_file', "Please enter a file name ");
  25.        }
  26.   }
  27.   else {
  28.     form_set_error('upload_file', "Please enter a file name:");
  29.   }
  30.   /*else {
  31.     if (!is_file($filePath))
  32.       form_set_error('upload_file', 'Please enter a valid file name.');
  33.    *
  34.    */
  35. }
  36. function crhub_crhubTestForm_submit($form, &$form_state) {
  37.   drupal_set_message(t('The form has been submitted.'));
  38.   dsm($form_state['values']);
  39.   /*debug ($form, 'Form ', false); */
  40.   $filePath = $form_state['values']['upload_file'];
  41.   include_once ('CMatArticleHandler.inc');
  42.   $Handler = new CMatArticleHandler($filePath, 'r');
  43.   $Handler->runMain('1');
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement