Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Afform - support file uploads #21150

Merged
merged 2 commits into from
Aug 27, 2021
Merged

Conversation

colemanw
Copy link
Member

Overview

Support file fields as part of Afform.

Technical Details

Adds a new API action Afform.submitFile which receives uploaded files one at a time after the form is submitted.

Comments

So far this supports adding but not removing files when updating an entity.

@civibot
Copy link

civibot bot commented Aug 16, 2021

(Standard links)

@civibot civibot bot added the master label Aug 16, 2021
@seamuslee001 seamuslee001 self-assigned this Aug 16, 2021
@seamuslee001
Copy link
Contributor

@colemanw

PHP Fatal error:  Cannot declare class api_v4_AfformCustomFieldUsageTest, because the name is already in use in /home/jenkins/bknix-dfl/build/core-21150-6yacd/web/sites/all/modules/civicrm/ext/afform/mock/tests/phpunit/api/v4/AfformFileUploadTest.php on line 161

@colemanw
Copy link
Member Author

Oops. Now fixed @seamuslee001

@seamuslee001
Copy link
Contributor

@colemanw I tried testing this filling in my test form as an anon user after adding a file upload field to the Constituent Information Custom field. I kept getting a 403 on the civicrm/ajax/api4/Afform/submitFile url

{
    "type": "form",
    "requires": [],
    "title": "Test Form",
    "description": "",
    "is_dashlet": false,
    "is_public": true,
    "is_token": false,
    "server_route": "civicrm/test-form-test",
    "permission": "*always allow*",
    "redirect": ""
}
<af-form ctrl="afform">
  <af-entity data="{contact_type: 'Individual', source: 'Test Form'}" url-autofill="0" type="Contact" name="Individual1" label="Individual 1" actions="{create: true, update: true}" security="FBAC" />
  <fieldset af-fieldset="Individual1">
    <legend class="af-text">Individual 1</legend>
    <fieldset class="af-container">
      <div class="af-container af-layout-inline" style="border: 1px solid #000000">
        <af-field name="first_name" />
        <af-field name="middle_name" />
        <af-field name="last_name" />
        <af-field name="birth_date" />
        <af-field name="display_name" />
        <af-field name="constituent_information.Test_File_Field" />
      </div>
    </fieldset>
  </fieldset>
  <button class="af-button btn-primary" crm-icon="fa-check" ng-click="afform.submit()">Submit</button>
</af-form>

@colemanw
Copy link
Member Author

@seamuslee001 good catch. I had forgotten to declare permissions for the new "submitFile" api action.
I've fixed it now.

Adds a new API action Afform.submitFile which receives uploaded files one at a time after the form is submitted.
@seamuslee001
Copy link
Contributor

Tested this and worked well this time

@seamuslee001 seamuslee001 merged commit b86ff14 into civicrm:master Aug 27, 2021
@seamuslee001 seamuslee001 deleted the afformUpload branch August 27, 2021 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants