CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Profile - custom data file field upload problem
Pages: [1] 2

Author Topic: Profile - custom data file field upload problem  (Read 5057 times)

joebaker

  • Guest
Profile - custom data file field upload problem
June 11, 2009, 02:22:05 am
I've created a custom data file field to allow users to upload a CV via their profile.

The problem is the field uploads fine if an administrator uploads the file through that user's contact data, BUT if user tries to upload the file themselves through their /user/UID/profile-form-name-here form then the file does not upload.

Permissions on the directories are all set properly.

Can anyone tell me what's up? Something I'm missing to make the file field usable by a non-administrator, maybe?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Profile - custom data file field upload problem
June 11, 2009, 07:05:40 am

We dont support file uploads on the my account / edit page (/user/UID/profile-form-name-here). This is a known bug.

Drupal controls that form and made it hard/impossible in 4.x/5.x. I suspect this is now doable via use of form_alter in drupal 6.x. If this is important to you please investigate and submit a patch and/or sponsor someone to do the same.

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

joebaker

  • Guest
Re: Profile - custom data file field upload problem
June 11, 2009, 07:30:14 am
Thanks for that pointer, Donald. That's helpful. Not sure I understand the CiviCRM API well enough yet to spend too much time on it, but may have a stab if i can find a moment.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Profile - custom data file field upload problem
June 11, 2009, 07:53:06 am

this is more knowing drupal form api well rather than civicrm api. basically you need to change the form to allow file uploads rather than a vanilla form

i.e. add:

enctype="multipart/form-data"

to the html form type

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Re: Profile - custom data file field upload problem
January 14, 2010, 12:10:00 pm
Is this all that is required to modify the form?  I"m using the user profiles and need to upload a file while in drupal.

I need to make this change too.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Profile - custom data file field upload problem
January 14, 2010, 03:43:43 pm

that is at least the first step, not sure what other changes will need to be done after that, but would be great if you can take a look and help move the issue forward

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Re: Profile - custom data file field upload problem
January 14, 2010, 09:53:12 pm
I added my function form_alter and according to the print_r of the $form array it contains the enctype attribute

    [#attributes] => Array
        (
            [enctype] => multipart/form-data
        )

When I submit it goes to mymodule_user function with the $op as form and as update, but non display the data of the form.  Where is good point to see if the file name and all that is trying to be saved.  I was looking for a submit type of function but coudn't find it.  Any ideas?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Profile - custom data file field upload problem
January 15, 2010, 07:18:14 am

check:

CRM/Profile/Form.php
CRM/Profile/Form/Edit.php

thats where most of the form creation code for profiles resides :).

You'll also need to check: packages/HTML/QuickForm.php and check on the upload action there

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Re: Profile - custom data file field upload problem
January 15, 2010, 10:38:47 pm
when submitting to save the page it gets to the CRM_Profile_Form::formRule function with the $files populated, but I don't see that the function does anything with the files
Code: [Select]
Array ( [custom_33] => Array ( [name] => bmdmilogo.jpg [type] => image/jpeg [tmp_name] => D:\xampp\tmp\php171.tmp [error] => 0 [size] => 31758 ) )

I found that in the CRM/Core/Form.php its where the multipart section of the form is added when a 'File' type field is added to the form.

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Re: Profile - custom data file field upload problem
January 17, 2010, 11:02:52 pm
I'm still lost here, it seems like the call to PostProcess is the one responsible for updating the custom fields in the database with the proper values, but when it calls it with the skipfile parameter as true, causing the file type fields not to be stored in the database.  This function is only called once in CRM/Dedupe/Finder/finder.php formatparams method.  i changed that to false but for some other reason my field is not present at this point, but it was when the formRule function is called. 

any other ideas greatly appreciated.


Code: [Select]
CRM_Core_BAO_CustomGroup::postProcess($tree, $fields, true);

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Re: Profile - custom data file field upload problem
January 18, 2010, 09:45:42 pm
I tested a profile in the testserver from civicrm and using the profile within civicrm it uploads the file successfully , but If i access it through the drupal's user profile the file is not uploaded.

From what I've gathered up until now the problem resides in two places
1. The CRM_Dedupe_Finder::formatParams only has 2 parameters fields and type.  the file custom field is in another array within the CMR_Profile_form:FormRule method.  Causing the file custom value not to be passed to the formatParams and also not passed to the CustomGroup::PostProcess function.
I temporarily patched the formatParams to merge the $fields and $files array resulting in a 3rd argument and led me to the next error.

2. Once the field file type gets to the custom group::postprocess function and process the file type field the arguments given to the post process are not correct.  The file I suppose exists on the server as the tmp_name element, but that is not given to the function.  I will changing that tomorrow and give it a try.


Code: [Select]
Jan 18 23:07:50  [info] DedupeFinder FIELDS Array
(
    [_qf_default] => Dynamic:submit
    [edit] => Array
        (
            [civicrm_dummy_field] => CiviCRM Dummy Field for Drupal
        )

    [MAX_FILE_SIZE] => 33554432
    [custom_32] => 123
    [custom_31] => ramses
    [custom_46] => 1228
    [custom_30] => usa
    [custom_59] => Array
        (
            [M] => 12
            [d] => 18
            [Y] => 2010
        )

    [custom_29] => Array
        (
            [M] => 10
            [d] => 1
            [Y] => 2010
        )

    [custom_53] => 1
    [custom_54] =>
    [custom_55] => Array
        (
            [M] =>
            [d] =>
            [Y] =>
        )

    [form_build_id] => form-e1fc0be005ba48b52804d41e6234adf4
    [form_token] => c7246b14f0f98b7b0ff1bb79a5ec649e
    [form_id] => user_profile_form
    [op] => Save
    [custom_33] => Array
        (
            [name] => bmdmilogo.jpg
            [type] => image/jpeg
            [tmp_name] => D:\xampp\tmp\php185.tmp
            [error] => 0
            [size] => 31758
        )

)


Jan 18 23:07:50  [info] DedupeFinder FLAT Array
(
    [_qf_default] => Dynamic:submit
    [edit.civicrm_dummy_field] => CiviCRM Dummy Field for Drupal
    [MAX_FILE_SIZE] => 33554432
    [custom_32] => 123
    [custom_31] => ramses
    [custom_46] => 1228
    [custom_30] => usa
    [custom_59.M] => 12
    [custom_59.d] => 18
    [custom_59.Y] => 2010
    [custom_29.M] => 10
    [custom_29.d] => 1
    [custom_29.Y] => 2010
    [custom_53] => 1
    [form_build_id] => form-e1fc0be005ba48b52804d41e6234adf4
    [form_token] => c7246b14f0f98b7b0ff1bb79a5ec649e
    [form_id] => user_profile_form
    [op] => Save
    [custom_33.name] => bmdmilogo.jpg
    [custom_33.type] => image/jpeg
    [custom_33.tmp_name] => D:\xampp\tmp\php185.tmp
    [custom_33.size] => 31758
)


Jan 18 23:07:50  [info] $CustomGroup: File  Array
(
    [name] => bmdmilogo.jpg
    [type] => image/jpeg
    [tmp_name] => D:\xampp\tmp\php185.tmp
    [error] => 0
    [size] => 31758
)

 = D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\CRM\Core\BAO\CustomGroup.php, backtrace, 1050
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\CRM\Dedupe\Finder.php, postProcess, 199
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\CRM\Profile\Form.php, formatParams, 514
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\CRM\Profile\Form\Dynamic.php, formRule, 120
, formRule,
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\packages\HTML\QuickForm.php, call_user_func, 1591
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\CRM\Core\Form.php, validate, 291
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\CRM\Core\QuickForm\Action\Submit.php, validate, 68
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\packages\HTML\QuickForm\Controller.php, perform, 203
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\packages\HTML\QuickForm\Page.php, handle, 103
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\CRM\Core\Controller.php, handle, 249
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\CRM\Core\BAO\UFGroup.php, run, 547
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\drupal\civicrm.module, getEditHTML, 562
D:\xampp\htdocs\drupal6\sites\all\modules\civicrm\drupal\civicrm.module, civicrm_form_data, 437
D:\xampp\htdocs\drupal6\modules\user\user.module, civicrm_user, 2481
D:\xampp\htdocs\drupal6\modules\user\user.pages.inc, _user_forms, 252
, user_profile_form,
D:\xampp\htdocs\drupal6\includes\form.inc, call_user_func_array, 371
, drupal_retrieve_form,
D:\xampp\htdocs\drupal6\includes\form.inc, call_user_func_array, 102
D:\xampp\htdocs\drupal6\modules\user\user.pages.inc, drupal_get_form, 237
, user_edit,
D:\xampp\htdocs\drupal6\includes\menu.inc, call_user_func_array, 348
D:\xampp\htdocs\drupal6\index.php, menu_execute_active_handler, 18

Jan 18 23:07:50  [info] $Fatal Error Details = Array
(
    [message] => Could not move custom file to custom upload directory
    [code] =>
)
[/code]

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Profile - custom data file field upload problem
January 19, 2010, 06:34:10 am

thanx for stepping up and doing this, and more importantly reporting back. if you get stuck or need any assistance ping us on IRC

this will be a useful addition to civicrm / drupal :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Re: Profile - custom data file field upload problem
January 19, 2010, 08:45:41 pm
Here are the patch files it still doesn't work.  With my changes it moves the file to the proper location but the incorrect name and then there is an error in the select for the entity table

This is the select
<code>SELECT    CF.id as cfID,
          CF.uri as uri,
          CF.mime_type as mime_type,
          CEF.id as cefID
FROM      civicrm_file AS CF
LEFT JOIN civicrm_entity_file AS CEF ON ( CEF.file_id = CF.id )
WHERE     CEF.entity_table = %1
AND       CEF.entity_id    = %2 AND CF.file_type_id = %3</code>
these are the parameters sent to the execution
Code: [Select]
(
    [1] => Array
        (
            [0] => civicrm_value_passport_information_6
            [1] => String
        )

    [2] => Array
        (
            [0] =>
            [1] => Integer
        )

    [3] => Array
        (
            [0] => 0
            [1] => Integer
        )

)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Profile - custom data file field upload problem
January 20, 2010, 01:22:26 pm

i got this to work on trunk with the help of your patches and a few more. i still need to clean it up and check all your fixes, but its likely this will make it into 3.1 :)

thanx for doing the research and getting this moving

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Re: Profile - custom data file field upload problem
January 20, 2010, 02:14:05 pm
Awsome news, how can I get to the changes? I can update to 3.1 if necessary.

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Profile - custom data file field upload problem

This forum was archived on 2017-11-26.