An upload/attachement field would be a great new feature :-)
Or is there already I way for users to add an attachment in the form ? (I couldn't find it)

CommentFileSizeAuthor
#4 file.inc.txt14.72 KBquicksketch

Comments

quicksketch’s picture

There is currently no way for a user to upload a file. We're working on making file uploads (along with other potential field types) easier to implement, similar to the flexinode module. I've posted similar information in this forum topic: http://drupal.org/node/59050.

kingofsevens’s picture

How about this? I read the forum topic and an idea pop'ed into my mind. You may already thought of this before. Here it is... oh btw I second the file upload field. =)

Why not use the upload module for this and keep the files in the folder files/webform/title/ (also can be files/title) then you can rename the file to submission_number.ext and keep only the path in the webform table. Then the module can email a text only mail and add the whole path to the mail for the admin to download.

Also when downloading csv. Drupal will zip the folder files/webform/title/ on the fly with csv.

And if you ever add the multipart email support you can make this as an option. What do you think? =)

quicksketch’s picture

Interesting idea, but I'm not sure if that kind of integration is possible. The upload module is made explicitely to upload files attached to nodes (ie. by clicking the 'edit' tab of the node). Webform should allow many files to be uploaded by anyone with 'view' priviledges and store them along with the submissions.

I'm glad you posted though, since you answered some of my questions I had meant to post a few days ago. I'll outline these questions in the next post.

quicksketch’s picture

StatusFileSize
new14.72 KB

I've attached a demo file.inc component that I encourage all interested individuals in trying out. This module will only work with the last few builds of the CVS version of webform.

Some particular options I'd like to consider in terms of file handling include:

  1. Where to store uploaded files:
  • Present administrators an option for each instance of the file component, whose default is equal to the Drupal setting for file uploads (or create a new folder in a subdirectory for each webform, as j-i-b suggested, I agree)
  • Present administrators with the option to set the upload location for all uploads to the same location in the webform preferences
  • Just dump all the files into the default files location with no setting (hey, someone might argue for it.)
  • Files will always be visible when viewing previous submissions, however I haven't decided if image types will be displayed differently than other files (ie, creating a thumbnail or displaying the original)
  • How to present emailed files:
    • Include a link back to the webform submission, where the file will be displayed. No file attached to the email.
    • Include the file as an attachment to the email
    • Or obviously, provide an option to do either one. The locations of this option would be the same as in point #1
  • I believe those most important considerations that I have yet to implement. I'm also open to suggestion as to how file filtering could be improved (you'll see what I've done so far in the attached module), both functionally and aesthetically.

    kingofsevens’s picture

    I have uploaded the module to my website and I tried it. I have added lots of fields.. but denied with several errors of different fields.

    user warning: Unknown column 'pid' in 'field list' query: INSERT INTO webform_component (nid, cid, pid, name, type, value, extra, mandatory, weight) VALUES ...

    I'll will try again.. and tell you later..

    Oh, I also added a RTF extension after PDF. I think that should be made available.

    kingofsevens’s picture

    Nope, nothing has changed... I'm using Drupal 4.7.2 with webform cvs with the file.inc. But there seems to be an error. I have tried with and w/o the file field. Here is the whole error message it says there is an error in the drupal database includes.

    user warning: Unknown column 'pid' in 'field list' query: INSERT INTO webform_component (nid, cid, pid, name, type, value, extra, mandatory, weight) VALUES (10, 1154079446, 0, 'Name', 'textfield', '', 'a:2:{s:11:\"description\";s:0:\"\";s:5:\"width\";s:2:\"20\";}', 1, -4) in /home/calinda/public_html/asistanbul/includes/database.mysql.inc on line 120.
    user warning: Unknown column 'pid' in 'field list' query: INSERT INTO webform_component (nid, cid, pid, name, type, value, extra, mandatory, weight) VALUES (10, 1154079473, 0, 'Languages', 'textfield', '', 'a:2:{s:11:\"description\";s:89:\"Please state the languages with a scale from 1 to 5. Ex: English (5), Portuguese (3), ...\";s:5:\"width\";s:2:\"20\";}', 1, -2) in /home/calinda/public_html/asistanbul/includes/database.mysql.inc on line 120.
    user warning: Unknown column 'pid' in 'field list' query: INSERT INTO webform_component (nid, cid, pid, name, type, value, extra, mandatory, weight) VALUES (10, 1154079515, 0, 'Cirriculum Vitæ', 'file', '', 'a:3:{s:11:\"description\";s:41:\"if you have a cv, please include it here.\";s:9:\"filtering\";a:3:{s:5:\"types\";a:1:{s:9:\"documents\";a:3:{s:3:\"doc\";s:3:\"doc\";s:3:\"pdf\";s:3:\"pdf\";s:3:\"rtf\";s:3:\"rtf\";}}s:13:\"addextensions\";s:0:\"\";s:4:\"size\";s:3:\"800\";}s:12:\"savelocation\";s:5:\"files\";}', 0, 0) in /home/calinda/public_html/asistanbul/includes/database.mysql.inc on line 120.

    or is it my problem?

    BachusII’s picture

    Uploaded as in "I did not have webform installed previously but now I do." or uploaded as in "I used to have webform installed, and now I have a newer version."?

    If the lather, you might have forgotten to visit the http://yoursite.com/update.php page. The database tables have changed, and your errormessages suggest to me the tables were not yet updated.

    haykelbj’s picture

    Hi,

    I tested the file upload component with the latest cvs version of webform (27.07.2006). I can add a file field, but when I submit the form I always get the error:
    "file field name" field is required.
    even though I selected a file with the file browser. Looking at the HTML source of the page, I noticed that all other fields have the names
    edit[submitted]["field name"]
    and the ids
    edit-submitted-"field name"
    while the file field has the name
    edit["field name"]
    and the id
    edit-"field name"
    (the submitted-keyword is missing). Could this be a hint for the problem?

    Another thing: It would be nice if information about the allowed max file size and extensions is added to the description of the file field.

    haykelbj’s picture

    Some other comments about the file field when it's not mandatory:

    • If I select a file, it works fine (the file is uploaded and it can be viewed in the results page)
    • If I let the field empty, I get the error Files with the '' extension are not allowed, please upload a file with a gif, jpg, png, doc, or pdf extension. The extensions are ok, they are the ones I selected when I added the field

    Hope this helps.

    haykelbj’s picture

    It's me again ;)

    * The 'field requiered' problem seems to be a bug in drupal (see my bug report http://drupal.org/node/76162). One workaround would be to always set the #required field for files to false and pass $component['mandatory'] to the _webform_validate_file() function and use it to test if the file have been submitted. The only problem is that the fields will not be marked as required (red *).

    * The extensions problem comes from the fact that in the _webform_validate_file() function, no test is done to see if no file was submitted. Using the same workaround as above, we would be able to test for this situation.

    Here are the needed changes (only the lines that need to be changed!):
    * Function _webform_render_file ($component):
    old:
    '#required' => $component['mandatory'],
    new:
    '#required' => false,

    old:
    '#validate' => array('_webform_validate_file' => array($component['name'],$component['extra']['filtering'])),
    new:
    '#validate' => array('_webform_validate_file' => array($component['name'],$component['extra']['filtering'],$component['mandatory'])),

    * Function _webform_validate_file ($component):
    old:
    function _webform_validate_file ($formelement,$fieldname,$filters) {
    new:

     function _webform_validate_file ($formelement,$fieldname,$filters,$mandatory) {
      if (!$file = file_check_upload($fieldname))
      {
        if (!$mandatory) return;
    
        form_set_error($fieldname, t('%name field is required.', array('%name' => $fieldname)));
        return;
      } 
    quicksketch’s picture

    Title: Upload field /attachement field for an user » File Component, Opinions wanted

    There are still several critical areas of code that have not yet been written for the file component. I'm mostly looking for suggestions at this point, not testing or bug-reports. I also forgot to mention the running update.php is necessary, as BachusII pointed out. Please make sure you backup your database before installing this new component, since it is still under development and further schema changes may be necessary.

    BachusII’s picture

    The attachment module (http://drupal.org/node/10245) might yield some interesting ideas.

    kingofsevens’s picture

    Okay, you were right BachusII, I didn't run the update.php. Now I did and it works fine with few problems. I know you don't want bug reports quicksketch, but here is a few I found you can check it before you start debugging. And if you ask me it is almost ready to release. The way it works is just fine. What do you guys think?

    - After you create a file field and return for editing it. When the page is displayed the web images in the upload filtering part are all selected even though they weren't when the field was saved.
    - The uploading directory works as long as it is "files". When you change it to "files/something" or "files/something/" it uploads the file to the a file named "something" in the "files" folder. And also it displayes the file name in the table view to "something" which is expected. When you upload the same file twice it names the other one to "something_0" with the same display name of "something" which is also expected but it may be better if it displayes "something_0". Well, this last part may not be related to the webform module but to drupal itself.
    - Also, sorry for writing this here. Now the downloaded file bares the extension ".csv.txt". Shouldn't it be ".csv" only?

    --- Oh, a zip for downloading the file would be nice.

    rose’s picture

    Where I have to put "file.inc.txt"?

    quicksketch’s picture

    jack in box: See http://drupal.org/node/76154 for why .txt is added. This affects all uploaded files in Drupal. Thanks for the note on changing the upload directory.

    rose: Remove the '.txt' from the file and drop it in 'modules/webform/components'. There should be several other files with '.inc' extensions there.

    rose’s picture

    Thank you so much . I got this error when i creat file attached field."warning: htmlspecialchars() expects parameter 1 to be string, array given in C:\AppServ\www\tongjitest\includes\bootstrap.inc on line 599. " what should I do?

    rose’s picture

    Sorry. it is working now after replacing 4.7 version with cvs version of webform. Thank and appreciated.

    kingofsevens’s picture

    @quicksketch: Have you seen this module? MimeModule, I have discovered it today. May be this can help but I really don't think it is necessary if you provide the url in the mail. BTW, url is not displayed in the mail just the name of the file.

    quicksketch’s picture

    Jack in the box: Thanks for the link. That's really cool. Maybe I'll put something in the default theme which includes an option for HTML mail if MIMEmail exists. After looking at this module, I agree we shouldn't include the image as an attachment. Maybe provide it as an option, I'm sure someone will request it eventually if I don't put it in initially.

    quicksketch’s picture

    Version: 4.7.x-1.x-dev »

    This component has now been commited to CVS.

    quicksketch’s picture

    Status: Active » Closed (fixed)
    unmesh20’s picture

    Version: » 6.x-2.9
    Assigned: Unassigned » unmesh20
    Priority: Normal » Critical
    Status: Closed (fixed) » Active

    i am working on school web site
    i need to create the staff details
    i create the fields through web Forms and upload the file as a staff image
    but in reports it shows as a attachment , insteas i wants to show image directly

    Please helped me out
    i am news to the Drupal

    Please write me the solution to following e mail

    unmesh.sonawane@gmail.com

    quicksketch’s picture

    Version: 6.x-2.9 » 4.7.x-1.x-dev
    Status: Active » Closed (fixed)

    Please open a new issue for this request.