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.
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.
}
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);
}
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
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.
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
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.
This should allow you to get the Record from TempData.
does var record = recordService.GetRecordFromTempData(TempData); give me a collection of every field from the form?
Yes it is whats stored in the database.
It seems that this code doesn't work for Forms 8.3.x (for Umbraco 8).
If you get the RecordService via
It doesn't include the method
GetRecordFromTempData()
.You can get the Record Id via:
And you can get all the Record data like this:
A bit cumbersome, but it works.
Doing a bit more exploring you can also do it all this way and avoid the intermediary page:
Then replace the Controller with yours in the
Form.cshtml
is working on a reply...