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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • File attachment
Pages: [1]

Author Topic: File attachment  (Read 1748 times)

awojidesylvester

  • Guest
File attachment
June 24, 2010, 07:13:37 am
 ??? Hello I have a problem and I hope you can help me fix it.

I created a custom field on joomla platform and the data type and field type was "file" for uploading/attaching documents...I added it to a profile, and linked it up with a membership registration page. I filled the fields for the registration page but it keeps returning the error below


 Please correct the following errors in the form fields below:

    * Files is a required field.

I was told on the forum to uncheck required...which I did and then tried filling the form again...but after filling the form, there is no indication that a file was uploaded....I even check the backend, an I still cant see  the form which I attached.
Please I really hope someone can help me with this.

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: File attachment
June 24, 2010, 11:48:36 am

based on your past forum posts, i'd highly recommend u hire someone from:

http://civicrm.org/professional/

to help you with installing and adapting civicrm for your org

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

awojidesylvester

  • Guest
Re: File attachment
June 25, 2010, 12:33:37 am
Thanks a lot for your response.

jyee

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: File attachment
September 17, 2010, 10:13:14 am
I'm getting the same error and I suspect Lobo didn't quite understand the problem (because this is a civicrm bug, not a custom integration issue).

Here's the scenario:
1. create a custom data file field in civicrm (e.g. your CV/resume)
2. add the field to a profile (e.g. member information) and make it required.
3. add the profile to a contribute/membership form.
4. try to use the form - despite adding files to the fields, when you submit the form, civicrm will return errors that the file fields are required.

I've made a demo here:
https://drupal.demo.civicrm.org/civicrm/contribute/transact?reset=1&action=preview&id=5
add a file and click confirm.  civi will return an error that the file field is required.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: File attachment
September 17, 2010, 11:32:28 am
Based on some quick additional testing - it looks like there's been some progress in the ability to include a custom file field in a profile in an online contribution page. I can successfully do this IF the custom field is USED FOR "Individuals" (probably works is USED FOR = "Contacts" as well). However, as shown in your example on the demo - it does not work properly if the custom field extends (is USED FOR) Memberships.

I would think that the "work around" of having the custom file  (e.g. CV/resume in your example) extend the person (USED FOR = Individual) would be manageable for many use cases. However, you can file an issue for a fix to the USED FOR = Memberships. If this approach is important to you - consider filing a patch with the issue.
Protect your investment in CiviCRM by  becoming a Member!

jyee

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: File attachment
September 17, 2010, 02:15:20 pm
Dave, thanks for the insight about for membership vs. individual/contact.  I'll give that a try and it should be an acceptable workaround for my current project.  I wish i had a larger budget and more time to correct the issue rather than working around it... maybe some other time.

jyee

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: File attachment
September 20, 2010, 10:01:40 am
Dave,

I upgraded to 3.2.3 (from 3.1.5) and i'm still receiving the file error, both when adding the custom field for individual and when trying it for membership.  I also tried again (using for individual) on the civicrm demo site (not sure which version that is), but ran into the same problem.

Since the "for=individual" setting doesn't seem to be a work around for me, any ideas on where I should start looking to fix this?

jyee

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: File attachment
September 20, 2010, 12:20:50 pm
Just an update from putting some devel dpm()'s in /CRM/Core/QuickForm/Action/Upload.php: it seems that the contribute pages instantiate the CRM_Core_QuickForm_Action_Upload class, but never actually call the upload() function.

So, essentially it's a dead field - shows up on the front, doesn't do anything on the back.

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: File attachment
September 20, 2010, 01:01:34 pm

all the forms instantiate ALL the actions, whether they are used or not (this is inherited from quickform controller)

if i had to guess, the contribute form is not modifying the form action to be an upload and hence the framework calls a plain form submit rather than a form upload

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

jyee

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: File attachment
September 20, 2010, 03:42:17 pm
Been working on this all day... here's what i've got:

CRM/Contribute/Form/Contribution/Main.php, around line 858:
Validation is run against fields, but not files, so required file fields would always fail.
changing this:
Code: [Select]
            if ( $fld['is_required'] &&
                 CRM_Utils_System::isNull( CRM_Utils_Array::value( $name, $fields ) ) ) {
                $errors[$name] = ts( '%1 is a required field.', array( 1 => $fld['title'] ) );
            } 

to this:
Code: [Select]
            if ( $fld['is_required'] &&
                 CRM_Utils_System::isNull( CRM_Utils_Array::value( $name, $files ) ) &&
                 CRM_Utils_System::isNull( CRM_Utils_Array::value( $name, $fields ) ) ) {
                $errors[$name] = ts( '%1 is a required field.', array( 1 => $fld['title'] ) );
            } 

seems to help. 

The file then appears to be successfully uploaded, but it never gets an entry into the civicrm_file table.  That causes an error when civi later tries to update the civicrm_value_custom_field_# table, because it receives null instead of the integer foreign key to civicrm_file. 

In CRM/Core/QuickForm/Action/Upload.php realPerform() about line 150, $page->mainProcess() doesn't do anything for contribute forms.  However, when editing a contact's membership, the file field works and that call passes off to something that then adds the correct entry in the civicrm_file table.

Hopefully all that makes sense.  In general, I'm just trying to compare membership (which works) to contribute (which doesn't)... I hope i'm going down the right track.

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: File attachment
September 20, 2010, 04:28:41 pm

on the demo if you make the profile field "files" not required (which i did), it uploads the file nicely and works

i would start off with that and get that working. Once u have that working, maybe a quick workaround might be to implement a validate hook to ensure that there is a file uploaded

http://wiki.civicrm.org/confluence/display/CRMDOC32/CiviCRM+hook+specification

once u have that working, u can circle back and figure out why the required stuff is not working in files. Ping us on IRC if u need help


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

jyee

  • I’m new here
  • *
  • Posts: 19
  • Karma: 3
Re: File attachment
September 20, 2010, 05:00:17 pm
Lobo,

Thanks... I had gone back to 3.1.5, but a combination of upgrading to 3.2.3 again and modifying CRM/Contribute/Form/Contribution/Main.php to check $files (instead of just $fields) seems to have done the trick.

So, for anyone who finds this thread later, here's the summary:

1. Upgrade to 3.2.3 (or later... might be fixed in earlier versions of 3.2 as well)
2. Modify your CRM/Contribute/Form/Contribution/Main.php file as described above.


Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: File attachment
September 21, 2010, 03:58:54 pm
I you have a general solution that fixes this and works properly for both 'required' and 'not required'  - you should file an issue with a patch attached.
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • File attachment

This forum was archived on 2017-11-26.