Copied to clipboard

Flag this post as spam?

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


  • naitsirhc 15 posts 117 karma points
    Feb 12, 2019 @ 07:49
    naitsirhc
    1

    trying to create a custom workflow.

    Hi, I am trying to create a custom workflow(I am totally lost how to do it), for a form that I have. I want the workflow to be able to redirect the user to a page based on which radiobutton they have selected on the form.

    For example. if the user select the first radio button, they would be redirected to the homepage or if they selected the second button they would be redirected to an external page on submit.

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Feb 12, 2019 @ 08:11
    Matthew Wise
    0

    Hi Christian,

    Workflows run post submit and the only one that can control user flow is the in built one.

    One way of achieving your goal is to redirect them to a generic success page. Then check the TempData for the submission id a d redirect from there.

    Matt

  • naitsirhc 15 posts 117 karma points
    Feb 12, 2019 @ 08:23
    naitsirhc
    0

    thanks!

    Umm, how would I go about checking the TempData for submission id??

    I'm new to Umbraco and its been a few years since I've written any code, so I am abit rusty.

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Feb 12, 2019 @ 08:47
    Matthew Wise
    100

    This should allow you to get the Record from TempData.

    var recordService = new Umbraco.Forms.Web.Services.RecordService();
    var record = recordService.GetRecordFromTempData(TempData);
    
    if(record != null){
    //TODO: check and redirect
    }
    else{
    //TODO: handle page load without record data.
    }
    
  • naitsirhc 15 posts 117 karma points
    Feb 12, 2019 @ 10:07
    naitsirhc
    0

    does var record = recordService.GetRecordFromTempData(TempData); give me a collection of every field from the form?

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Feb 12, 2019 @ 10:08
    Matthew Wise
    0

    Yes it is whats stored in the database.

  • Heather Floyd 610 posts 1032 karma points MVP 6x c-trib
    Apr 01, 2020 @ 21:26
    Heather Floyd
    3

    It seems that this code doesn't work for Forms 8.3.x (for Umbraco 8).

    If you get the RecordService via

    var recordService = Current.Factory.GetInstance<IRecordService>();
    

    It doesn't include the method GetRecordFromTempData().

    You can get the Record Id via:

    Guid recordId = Guid.Empty;
    if (TempData.ContainsKey("Forms_Current_Record_id"))
    {
        recordId = (Guid)TempData["Forms_Current_Record_id"];
    }
    

    And you can get all the Record data like this:

    var recordStorage = Current.Factory.GetInstance<IRecordStorage>();
    var formService = Current.Factory.GetInstance<IFormService>();
    
    Guid recordId = Guid.Empty;
    if (TempData.ContainsKey("Forms_Current_Record_id"))
    {
        recordId = (Guid)TempData["Forms_Current_Record_id"];
    }
    
    var formId = Guid.Empty;
    if (TempData.ContainsKey("UmbracoForms"))
    {
        var valUmbracoForms =(IEnumerable<Guid>) TempData["UmbracoForms"];
        formId =valUmbracoForms.First(); 
    }
    
    Record record = null;
    Form form = null;
    if (recordId != Guid.Empty && formId != Guid.Empty)
    {
        form = formService.GetForm(formId);
        record = recordStorage.GetRecordByUniqueId(recordId, form);
    }
    

    A bit cumbersome, but it works.

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Feb 12, 2019 @ 08:53
    Matthew Wise
    0

    Doing a bit more exploring you can also do it all this way and avoid the intermediary page:

    public class MyFormsController : UmbracoFormsController
    {
         protected override void OnFormHandled(Form form, FormViewModel model)
          {
              //example of how to access fieldData
               var field = form.AllFields.FirstOrDefault(x => x.Alias == "deliveryOptions");
               var fieldValue = model.FormState[field.Id.ToString()].GetValue(0).ToString();
    
               form.GoToPageOnSubmit = <pageId>;
          }
    }
    

    Then replace the Controller with yours in the Form.cshtml

Please Sign in or register to post replies

Write your reply to:

Draft