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

Override Submitted partial for specific form #898

Closed
bjarnef opened this issue Oct 18, 2022 · 6 comments
Closed

Override Submitted partial for specific form #898

bjarnef opened this issue Oct 18, 2022 · 6 comments

Comments

@bjarnef
Copy link

bjarnef commented Oct 18, 2022

It is possible to override form fields for a specific form:
https://our.umbraco.com/documentation/Add-ons/umbracoforms/developer/custom-markup/#customizing-for-a-specific-form

I tried the same for default Submitted.cshtml as we want to list the data from the record below the message.

However it doesn't quite seem to work?

I tried with:

~\Views\Partials\Forms\115dd2b5-1eeb-421a-bf20-d96023482750\Submitted.cshtml
~\Views\Partials\Forms\themes\standard\115dd2b5-1eeb-421a-bf20-d96023482750\Submitted.cshtml

However it works fine it placed inside

~\Views\Partials\Forms\themes\standard\Submitted.cshtml

Not sure if it should work, but I think I saw another issue or discussion on https://our.umbraco.com that overriding by Form ID (Guid) didn't work.

Umbraco v10.2.1
Forms v10.1.2

@AndyButland
Copy link

I believe this functionality was removed yes (at least I see no evidence in the code that this should work), but I don't know the history behind it I'm afraid. Could be something we look to reinstate though.

@bjarnef
Copy link
Author

bjarnef commented Oct 18, 2022

Okay, it would be great to mention this in the documentation here for now: https://our.umbraco.com/documentation/Add-ons/umbracoforms/developer/custom-markup/#customizing-for-a-specific-form

However I workaround it to put it in ~\Views\Partials\Forms\themes\standard\Submitted.cshtml

Then I have this:

@if (Model.FormId == Guid.Parse("115dd2b5-1eeb-421a-bf20-d96023482750"))
{
    @await Html.PartialAsync("Forms/CourseRegistration", Model)
}

where Model is Umbraco.Forms.Web.Models.FormViewModel

and in the partial CourseRegistration I have something like this for now:

@model Umbraco.Forms.Web.Models.FormViewModel

@inject Umbraco.Forms.Core.Data.Storage.IRecordStorage _recordStorage;

@{
    var record = _recordStorage.GetRecord(Model.RecordId);
}

In the email templates these inherits Umbraco.Forms.Core.Models.FormsHtmlModel though.

@inherits UmbracoViewPage<Umbraco.Forms.Core.Models.FormsHtmlModel>

Is there service to get the the form / record as Umbraco.Forms.Core.Models.FormsHtmlModel?

@bjarnef
Copy link
Author

bjarnef commented Oct 18, 2022

I noticed when I output @Model.RecordId in Submitted.cshtml is returns an empty guid.

Is that expected?

However @TempData["Forms_Current_Record_id"] returns a guid.

image

which you also blogged about here @AndyButland
https://www.andybutland.dev/2022/04/getting-submitted-form-data-in-umbraco.html

@AndyButland
Copy link

That RecordId property is currently only populated from the querystring provided when an existing record is being edited on the front-end (i.e. if you have enabled the option to allow form entries to be edited). It's not getting set to the new record Id created when a normal form entry is made. Arguably it should be...

The construction of FormFieldHtmlModel isn't exposed I'm afraid (i.e. it's using private methods within the send email workflow).

@bjarnef
Copy link
Author

bjarnef commented Oct 18, 2022

I think it could have something like this:

@inject Umbraco.Forms.Web.Services.IFormRenderingService _formRenderingService;

@{
    Guid.TryParse(TempData["Forms_Current_Record_id"]?.ToString(), out Guid recordId);
    
    var record = _formRenderingService.GetRecord(recordId);
}

However I found it a bit inconsistent in this service: Umbraco.Forms.Web.Services.IFormRenderingService

image

where Record is a dto class while Form and FormViewModel are more intended to use in views.

Sometimes I am missing a GetRecordModel()or similar.

But it seems TempData["Forms_Current_Record_id"] is only available after form submission ... on page reload it seems to be lost.

@AndyButland
Copy link

Will close this one as the original issue is duplicated by #860.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants