umbraco / Umbraco.Forms.Issues

Public issue tracker for Umbraco Forms
29 stars 0 forks source link

Programatically creating a Umbraco Form Record with State = PartiallySubmitted gets saved as Approved #1186

Closed tenshi04 closed 6 months ago

tenshi04 commented 6 months ago

A brief description of the issue goes here.

Reference to example here: https://www.andybutland.dev/2023/04/blog-post.html

Just before I call a _recordService.Submit, I do this:

record.State = FormState.PartiallySubmitted; _recordService.Submit(record, form);

When I view the record in the database in the UFRecords table, the state is "Approved"

Reproduction

If you're filing a bug, please describe how to reproduce it. Include as much relevant information as possible, such as:

Bug summary

Follow steps in https://www.andybutland.dev/2023/04/blog-post.html

Expected result

I would expect the state to remain as PartiallySubmitted

Actual result

The state for the record is Approved

AndyButland commented 6 months ago

This is expected actually. By calling "Submit" you will be setting the status to "Submitted", it's part of the behaviour of the method you are calling. And if you have a form configured not for manual approval, it'll automatically approved and the status set to "Approved". "PartiallySubmitted" looks to be a legacy setting and isn't used in the Forms code base anymore.

There is a lower-level class you can inject - IRecordStorage - that has an InsertRecord method and here it's all about just saving exactly what you send it (internally, IRecordService depends on IRecordStorage. So there what you set it to for state should be retained. But this won't fire workflows or other notifications that the service layer does.

tenshi04 commented 6 months ago

Thank you for the explanation Andy.

We're trying to implement something like this for Umbraco 8

https://our.umbraco.com/forum/umbraco-forms/87608-multi-page-form-save-data

We're trying to save intermediate stages of a multi-page form so that a user/member can come back to it and continue where they left of. Do you happen to have any ideas/samples to do this in Umbraco 8?

Thanks.

Classification: Protected A

From: Andy Butland @.> Sent: Monday, March 11, 2024 11:29 PM To: umbraco/Umbraco.Forms.Issues @.> Cc: Angelbert David @.>; Author @.> Subject: Re: [umbraco/Umbraco.Forms.Issues] Programatically creating a Umbraco Form Record with State = PartiallySubmitted gets saved as Approved (Issue #1186)

CAUTION: This email has been sent from an external source. Treat hyperlinks and attachments in this email with care.

This is expected actually. By calling "Submit" you will be setting the status to "Submitted", it's part of the behaviour of the method you are calling. And if you have a form configured not for manual approval, it'll automatically approved and the status set to "Approved". "PartiallySubmitted" looks to be a legacy setting and isn't used in the Forms code base anymore.

There is a lower-level class you can inject - IRecordStorage - that has an InsertRecord method and here it's all about just saving exactly what you send it (internally, IRecordService depends on IRecordStorage. So there what you set it to for state should be retained. But this won't fire workflows or other notifications that the service layer does.

- Reply to this email directly, view it on GitHubhttps://github.com/umbraco/Umbraco.Forms.Issues/issues/1186#issuecomment-1990566606, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABTYOSXTZWWKMMMIXLL7T73YX2HC5AVCNFSM6AAAAABERC5GN2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJQGU3DMNRQGY. You are receiving this because you authored the thread.Message ID: @.***>

AndyButland commented 6 months ago

You'll probably want to look at the setting for allowing editable form submissions. This allows you to provided GUID in the querystring of your page that allows the record matching that GUID to be edited. So you could share that as a link to the user's entry for update.

When you submit an entry as a logged in member, the member's ID is associated with the record, so you could use that to generate the links for the member to edit their form.

You'll need to consider carefully the security side of that, and prevent people people editing records they don't own.

tenshi04 commented 6 months ago

Thanks for the tips. We have set AllowEditableFormSubmissions to True, and we do see the member's ID attached to the record when submitted.

The one challenge that I am having with the sample code is that with each 'next' button click:

Ideally, we'd like to keep updating the 'same' record with each next click and finally set it to 'Approved' or 'Submitted' when the user actually submits.

Classification: Protected A

From: Andy Butland @.> Sent: Tuesday, March 12, 2024 7:42 AM To: umbraco/Umbraco.Forms.Issues @.> Cc: Angelbert David @.>; Author @.> Subject: Re: [umbraco/Umbraco.Forms.Issues] Programatically creating a Umbraco Form Record with State = PartiallySubmitted gets saved as Approved (Issue #1186)

CAUTION: This email has been sent from an external source. Treat hyperlinks and attachments in this email with care.

You'll probably want to look at the setting for allowing editable form submissionshttps://docs.umbraco.com/umbraco-forms/developer/configuration#alloweditableformsubmissions. This allows you to provided GUID in the querystring of your page that allows the record matching that GUID to be edited. So you could share that as a link to the user's entry for update.

When you submit an entry as a logged in member, the member's ID is associated with the record, so you could use that to generate the links for the member to edit their form.

You'll need to consider carefully the security side of that, and prevent people people editing records they don't own.

- Reply to this email directly, view it on GitHubhttps://github.com/umbraco/Umbraco.Forms.Issues/issues/1186#issuecomment-1991682349, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABTYOSXMLAALZB7ZNAYUFQTYX4A3VAVCNFSM6AAAAABERC5GN2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJRGY4DEMZUHE. You are receiving this because you authored the thread.Message ID: @.***>