upload module

crinch - November 6, 2007 - 09:52

Hi Guys,

I am creating a new module, in that module there are several forms on one page with collapsible links. I want to inculde 'File Attachments' collapsible link that uploads the image in that same page without redirecting to any page.
I am not getting the code which I could extract from the upload module and put it into my forms, so every form will have option to upload the image with blogs,albums,images.....

I need your help. Thanks in advance.

CRINCH

I am adding this bloc of

crinch - November 6, 2007 - 11:39

I am adding this bloc of code with every form but it is working with only first form.......

function test_page($gid = NULL) {
// cache_clear_all('*', 'cache', TRUE);
  $forms_arr = array('acidfree','blog','article','event','invitation', 'image');
  for($i=0; $i<count($forms_arr); $i++){
  $output .= drupal_get_form('test_form_'.$forms_arr[$i], $forms_arr[$i], $gid);
  }     
  return $output;
} // end of function test_page
function test_form_acidfree($cat_arr, $gid = NULL){
$form['#id'] = 'test_form_'.$cat_arr;   
$form['newsite_acidfree'] = array(
  '#type' => 'fieldset',
  '#title' => t('Would you start your photo album now?'),
  '#weight' => 3,
   '#collapsible' => TRUE,
   '#collapsed' => TRUE,
   '#prefix' => '<div class="node-form">',
   '#suffix' => '</div>',
);
$form[newsite_acidfree]..
...
...
..


//////////////////////////////////////start upload odule////////////////////////////////////////////////////////////////////
      drupal_add_js('misc/progress.js');
      drupal_add_js('misc/upload.js');
      $form['newsite_acidfree']['attachments'] = array(
        '#type' => 'fieldset',
        '#access' => user_access('upload files'),
        '#title' => t('File attachments'),
        '#collapsible' => TRUE,
        '#collapsed' => empty($node->files),
        '#description' => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
        '#prefix' => '<div class="attachments">',
        '#suffix' => '</div>',
        '#weight' => 30,
      );
      // Wrapper for fieldset contents (used by upload JS).
      $form['newsite_acidfree']['attachments']['wrapper'] = array(
        '#prefix' => '<div id="attach-wrapper">',
        '#suffix' => '</div>',
      );
      // Make sure necessary directories for upload.module exist and are
      // writable before displaying the attachment form.
      $path = file_directory_path();
      $temp = file_directory_temp();
      // Note: pass by reference
      if (!file_check_directory($path, FILE_CREATE_DIRECTORY) || !file_check_directory($temp, FILE_CREATE_DIRECTORY)) {  
        $form['newsite_acidfree']['attachments']['#description'] =  t('File attachments are disabled. The file directories have not been properly configured.');
        if (user_access('administer site configuration')) { 
          $form['newsite_acidfree']['attachments']['#description'] .= ' '. t('Please visit the <a href="@admin-file-system">file system configuration page</a>.', array('@admin-file-system' => url('admin/settings/file-system')));
        }
        else {
          $form['newsite_acidfree']['attachments']['#description'] .= ' '. t('Please contact the site administrator.');
        }
      }
      else {
        $form['newsite_acidfree']['attachments']['wrapper'] += _upload_form($node);
        $form['newsite_blog']['#attributes']['enctype'] = 'multipart/form-data';
      }  
return $form;
} // end of function test_form_acidfree  
//////////////////////////////////////////////end /////////////////////////////////////////////

This code play the processing bar while uploading a file but did not mention the uploading file after that.
All these forms are being developed in one event/action.
Only first form shows the processing bar while uploading the attachment not remaining but form is submitted.
How I can handle this.....
Thanks in advance.

CRINCH

I'm guessing a bit here but

gpk - November 7, 2007 - 10:07

I'm guessing a bit here but I think the upload.module is intended for uploading attachments to nodes with the assumption that there will only be one node being edited at a time with a single Attachments control on the web page.

Hence I don't know if '#collapsed' => empty($node->files),' will work for you. However this is not the big problem.

Each form is going to include something like this section of code that you posted:

      // Wrapper for fieldset contents (used by upload JS).
      $form['newsite_acidfree']['attachments']['wrapper'] = array(
        '#prefix' => '<div id="attach-wrapper">',
        '#suffix' => '</div>',
      );

round the Attachments fieldset, i.e. they are all wrapped in <div>s with the same id. I assume upload.js uses the id to grab the upload control - this would be why only the first one works.

You may want to have a look at the UpAPI (upload API) module, and if you *are* attaching your uploads to node(s) then you may also want to have a look at CCK and the CCK filefield modules. Also here is a list of upload-related modules.

gpk
----
www.alexoria.co.uk

thank you very much for you

crinch - November 8, 2007 - 14:49

thank you very much for you consideration.
The problem is that it does not complete the whole process with the first div. It just showed the progress bar and then show the new input file beneath that. That is the end.
I want that at least the first div should be done accurately, it should show the complete behavior as it does in its default module.
I am sure, you have got my problem and can help me. Thanks in advance.

Crinch

What are you trying to

gpk - November 8, 2007 - 15:02

What are you trying to attach the attachment to? What is wrong with the process for the first div? It sounds as though it upload the file OK? - you say it shows the progress bar and then shows the attachment when it is finished.

gpk
----
www.alexoria.co.uk

Thank you..... If you use

crinch - November 9, 2007 - 05:38

Thank you.....
If you use the og group in that we go to add something like that 'node/add/acidfree, node/add/blog, node/add/image,....'. Every form of this event has the 'File Attachment' option in the bottom of the form. If you observe 'File Attachment's' behavior in these forms. It displays a dive that shows the recently attached files with remove,size,description options after finishing progressing bar and then a 'new upload file' field is placed beneath that div to attach a new file.
My problem is that id does not show that div of recently attached files after finishing progressing bar. I have already put the code that I have used for this after extracting from the upload module. Please help is required to show that div which shows the recently attached files after finishing progressing bar.

Thanks in advance.
CRINCH

Thanks for the

gpk - November 9, 2007 - 09:39

Thanks for the clarification.

One more question:
What are you trying to attach the attachment to?

gpk
----
www.alexoria.co.uk

its a skype gif Thank you

crinch - November 9, 2007 - 12:27

its a skype gif
Thank you for your consideraiton and waiting for your answer

CRINCH

Hmmm what you are trying to

gpk - November 9, 2007 - 16:01

Hmmm what you are trying to do looks OK - I'm assuming that $node is properly defined and that you have enabled uploads for the relevant content type(s)? Otherwise I can't see what the problem is. Maybe it fails because you have more than one upload control on the form, and each has the same id? If you want multiple upload controls you either need to customise _upload_form() or use UpAPI as I mentioned above.

gpk
----
www.alexoria.co.uk

thank you for your

crinch - November 12, 2007 - 06:56

thank you for your consideration.
I have downloaded the the module UpAPI but don't know how to use that according to my requirement means multiple upload controls with multiple forms...

Thanks
CRINCH

I've not used it either but

gpk - November 15, 2007 - 10:41

I've not used it either but it looks as though multiple upload fields are possible. I think the trick is to set #label correctly. Have a look at the example.

Note that "Javascripty goodness like progress bar, etc." is currently on the wishlist for the UpAPI module.

Good luck!

gpk
----
www.alexoria.co.uk

 
 

Drupal is a registered trademark of Dries Buytaert.