Skip to content

Commit

Permalink
#104 - add more handling of empty/missing forms
Browse files Browse the repository at this point in the history
  • Loading branch information
kjac committed Dec 21, 2016
1 parent f9a4eb7 commit 070bf45
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Source/Solution/FormEditor/FormModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ public FieldValueFrequencyStatistics<IStatisticsField> GetFieldValueFrequencySta
return result;
}

public bool IsEmpty()
{
return Pages == null;
}

private HttpRequest Request
{
get { return HttpContext.Current.Request; }
Expand Down
8 changes: 4 additions & 4 deletions Source/Umbraco/Views/Partials/FormEditor/Async.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// get the form model
var form = formContent.GetPropertyValue<FormModel>(formPropertyName);

// #104 - don't break the site if the form model could not be found
if(form == null)
// #104 - don't attempt to render the form if the form model does not exist on the page or if it is empty
if(form == null || form.IsEmpty())
{
@: <!-- no Form Editor form was found on the page -->
return;
Expand All @@ -24,9 +24,9 @@
if(ViewBag.FormRowId is string)
{
Guid rowId;
if(Guid.TryParse((string) ViewBag.FormRowId, out rowId))
if(Guid.TryParse((string)ViewBag.FormRowId, out rowId))
{
form.LoadValues(formContent, rowId);
form.LoadValues(formContent, rowId);
}
}

Expand Down
8 changes: 4 additions & 4 deletions Source/Umbraco/Views/Partials/FormEditor/NoScript.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

// get the name of the form model property on the content type (defaults to "form")
var formPropertyName = ViewBag.FormName as string ?? "form";

// get the form model
var form = formContent.GetPropertyValue<FormModel>(formPropertyName);

// #104 - don't break the site if the form model could not be found
if(form == null)
// #104 - don't attempt to render the form if the form model does not exist on the page or if it is empty
if(form == null || form.IsEmpty())
{
@: <!-- no Form Editor form was found on the page -->
return;
Expand All @@ -26,7 +26,7 @@
form.LoadValues(formContent, rowId);
}
}

// handle form submission if this is a postback
// - this will also take care of redirecting to the success page (if configured)
var formWasSubmitted = form.CollectSubmittedValues(formContent);
Expand Down
8 changes: 4 additions & 4 deletions Source/Umbraco/Views/Partials/FormEditor/Sync.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

// get the name of the form model property on the content type (defaults to "form")
var formPropertyName = ViewBag.FormName as string ?? "form";

// get the form model
var form = formContent.GetPropertyValue<FormModel>(formPropertyName);

// #104 - don't break the site if the form model could not be found
if(form == null)
// #104 - don't attempt to render the form if the form model does not exist on the page or if it is empty
if(form == null || form.IsEmpty())
{
@: <!-- no Form Editor form was found on the page -->
return;
Expand All @@ -27,7 +27,7 @@
form.LoadValues(formContent, rowId);
}
}

// handle form submission if this is a postback
// - this will also take care of redirecting to the success page (if configured)
var formWasSubmitted = form.CollectSubmittedValues(formContent);
Expand Down

0 comments on commit 070bf45

Please sign in to comment.