Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Jacobsen 597 posts 2395 karma points
    Jan 20, 2016 @ 11:12
    Bo Jacobsen
    0

    Forms Workflow. Auto fillout form and find former record.

    Hello again everyone..

    I am using Umbraco Forms (not the contour plugin).

    Is there a way to fill out a form with record data. If the user already have typed in data and its stored as a record. And if so, how would i do that?

    (Let's say, i filled out the form and hit submit. Then i come to a summary page. But i found out that some of the details i have entered is wrong. Then i hit the back button and gets redirected back to the form.)

    Next i have some workflow question. I have made some comments in the code below, where i dunno what to do. And hope some kind souls can help me a little.

    public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
            var rs = new RecordStorage();
            var oldRecord =
                rs.GetAllRecords(e.Form)
                    .FirstOrDefault(
                        r =>
                            r.GetRecordField("email")
                                .ValuesAsString()
                                .ToLower()
                                .Equals(record.GetRecordField("email").ValuesAsString().ToLower()));
            if (oldRecord != null)
            {
                if (oldRecord.State == FormState.Submitted)
                {
                    // How to update the oldRecord to record.
                }
                else
                {
                    rs.DeleteRecord(record, e.Form);
                    return WorkflowExecutionStatus.Cancelled;
                }
            }
            rs.Dispose();
    
            // Now i need the data from the record to be stored into TempData or a Session in order to use it again on the nextpage as summary page.
            // Or to use to fillout the form again if the user hit the back button to edit the data they entered.
    
            return WorkflowExecutionStatus.Completed;
        }
    
  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jan 22, 2016 @ 09:02
    Warren Buckley
    0

    Hello Bo,

    I am trying to understand your requirements here to help answer you correctly.

    Am i right in thinking after the form has been submitted you wish to revisit the form & amend/edit the form?

    If so I don't think using the back button will work as the browser will just reload the page and see it as a new form submission and hence be blank.

    What I can recommend or suggest is that after the form is submitted you keep a note of the form submission/record ID and then you can revisit the page with the form on and append a querystring that will repopulate the form.

    As I have recently joined the team to work on Forms at the HQ, I need to go away & put this theory into practise and come back with a sample for you.

    In regards to the second part of your question with the workflow item, can you explain the bigger picture in what you are trying to achieve to see if I can help with your problem.

    Thanks,
    Warren

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jan 22, 2016 @ 10:48
    Warren Buckley
    1

    Hello Bo,
    Following up from my earlier post I can tell you that after a form submission using 'Forms' there are 4 items added to the TempData dictionary object that you can use as you need.

    TempData["UmbracoForms"] contains the Form ID/Guid

    TempData["umbracoformsrecord"] contains a dictionary object of key/value pairs of the Field ID/guid & it's value that was posted in the form.

    TempData["Forms_Current_Record_id"] contains the unique ID of the submitted record.

    so you can use this to retrieve the record from the API as needed or in our case use it to create a link back to our page with our form & appending the querystring.

    The final item in the TempData for reference is TempData["umbracoformsform"] which is a strongly typed object of Umbraco.Forms.Mvc.Models.FormViewModel

    For us to reload the same form for editing purposes we will need the guid of the record stored in Forms_Current_Record_id to build up a link to get the nice friendly integer version needed by querying the RecordService.

    @{
        //Gets the Record Unique Guid and gets us the Record object
        //We only need it's Id to pass as the QS param
        var record = RecordService.Instance.GetRecordFromTempData(TempData);
        var recordId = 0;
    
        if (record != null)
        {
            recordId = record.Id;
        }
    }
    
    @if (recordId > 0)
    {
        <a href="?recordID=@recordId">Edit Record</a>
    }
    

    I hope this helps you and was what you was after Bo.

    Thanks,
    Warren

  • Bo Jacobsen 597 posts 2395 karma points
    Jan 22, 2016 @ 12:32
    Bo Jacobsen
    0

    I will try play around with it, when i come back to work. Then i will come back to you.

    Thanks for helping out so far :)

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jan 22, 2016 @ 14:32
    Warren Buckley
    0

    No problem Bo,
    Let me know how it goes.

    Warren

  • Bo Jacobsen 597 posts 2395 karma points
    Jan 25, 2016 @ 11:22
    Bo Jacobsen
    1

    Okay i have tried to play around with it alittle bit.

    If i use [deleted] i get the data filled in the form by its recordId as i would like too. BUT i can get any former records if i got the right id. And thats a problem. We tested it on other forms from other sites. And we where able to get the user data if we typed in the right id. Thats a big security risk.

  • Bo Jacobsen 597 posts 2395 karma points
    Jan 26, 2016 @ 10:50
    Bo Jacobsen
    0

    Also if i use a querystring and the Form is in steps. Then it only auto fill out former data on the first step it lands on.

    I also cant seem to figure out how to update a record to approved manuel.

    var record = RecordService.Instance.GetRecordFromTempData(TempData);
            var recordId = 0;
            if (record != null)
            {
                var rs = new RecordService();
                rs.Approve(record, TempData["umbracoformsform"] as Form);
            }
    
  • Per Ploug 865 posts 3491 karma points MVP admin
    Jan 26, 2016 @ 11:13
    Per Ploug
    0

    Hey Bo, thanks for the details, a new version is being built and shipped today which will fix that issue - I took the liberty of removing the details from your posts

  • Bo Jacobsen 597 posts 2395 karma points
    Jan 27, 2016 @ 09:04
    Bo Jacobsen
    0

    Yes i understand :)

    Could you give an exsample of, how to update a record to approved state? Then i would be happy.

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Jan 27, 2016 @ 14:23
    Warren Buckley
    100

    Hello Bo,
    As Per mentions the 4.1.5 release is out & deals with that issue.

    In regards to updating a form record from submitted to approved using code, then you can use the following below:

    //Gets the Record Unique Guid and gets us the Record object
    var record = RecordService.Instance.GetRecordFromTempData(TempData);
    
    if (record != null)
    {
        Umbraco.Forms.Data.Storage.RecordStorage storage = new Umbraco.Forms.Data.Storage.RecordStorage();
        Umbraco.Forms.Data.Storage.FormStorage formStorage = new Umbraco.Forms.Data.Storage.FormStorage();
    
    
        //Get the record by its Record ID
        //Umbraco.Forms.Core.Record record = storage.GetRecordByUniqueId("GUID-HERE");
    
        //Get the Form by finding out what Form the Record was submitted from
        Umbraco.Forms.Core.Form form = formStorage.GetForm(record.Form);
    
        //Record Service - Approve Record
        RecordService.Instance.Approve(record, form);
    }
    

    I hope this helps you with what you need Bo. If not I am happy to help you futher.

    Cheers,
    Warren :)

  • Bo Jacobsen 597 posts 2395 karma points
    Feb 05, 2016 @ 13:18
    Bo Jacobsen
    0

    I got it working using my own session to store the record in.

    My TempData is null when i use it like this.

    // On the same view i use
    if (request.HttpMethod == "POST")
    {
        // Here the record will be null
        var sameRecord = RecordService.Instance.GetRecordFromTempData(TempData);
        if (sameRecord != null)
        {
            Umbraco.Forms.Data.Storage.RecordStorage storage = new Umbraco.Forms.Data.Storage.RecordStorage();
            Umbraco.Forms.Data.Storage.FormStorage formStorage = new Umbraco.Forms.Data.Storage.FormStorage();
    
            Umbraco.Forms.Core.Form form = formStorage.GetForm(sameRecord.Form);
    
            RecordService.Instance.Approve(sameRecord, form);
        }
    
    }
    // Here the record work as it should
    var record = RecordService.Instance.GetRecordFromTempData(TempData);
    // Then i fill out the preview before the user submits.
    
Please Sign in or register to post replies

Write your reply to:

Draft