NL LOGIN Arrow right
U gebruikt een verouderde browser. Gebruik Google Chrome of Mozilla Firefox om uw ervaring te verbeteren.
Error executing template "Designs/Huuskes/Forms/Form/WinActionForm.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Huuskes.Repository.Helpers.ItemHelper.GetItemValue[T](Item item, String itemFieldSystemName) in D:\a\1\s\Huuskes.Repository\Helpers\ItemHelper.cs:line 11
at CompiledRazorTemplates.Dynamic.RazorEngine_c773b46d562d4e6eaea436d543a8356a.Execute() in D:\inetpub\wwwroot\www.huuskes.nl\Files\Templates\Designs\Huuskes\Forms\Form\WinActionForm.cshtml:line 38
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @using Huuskes.Repository.Helpers 2 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 3 @{ 4 var pageView = Dynamicweb.Frontend.PageView.Current(); 5 string formCssClass = GetString("Form.CssClass"); 6 string formSystemFields = GetString("Form.SystemFields"); 7 bool formLabelBold = GetBoolean("Form.LabelBold"); 8 bool formLabelOverField = GetBoolean("Form.LabelOverField"); 9 string formId = GetString("Form.HtmlId"); 10 string formOnSubmit = MailHelper.FixTargetPageID(GetString("Form.OnSubmit"), pageView); 11 string formSpamScript = GetString("Form.SpamScript"); 12 string formAction = GetString("Form.Action"); 13 int formColumnShiftFormFieldID = GetInteger("Form.ColumnShiftFormFieldID"); 14 string formLabelRequired = GetString("Form.LabelRequired"); 15 if (string.IsNullOrWhiteSpace(formLabelRequired)) 16 { 17 formLabelRequired = "<span>*</span>"; 18 } 19 int formMaxSubmits = GetInteger("Form.MaxSubmits"); 20 int formSubmitCount = GetInteger("Form.SubmitCount"); 21 string[] showInlineFieldTypes = { "CheckBox", "CheckBoxList", "Radio" }; 22 23 if (formMaxSubmits > 0 && formSubmitCount >= formMaxSubmits) 24 { 25 @GetString("Form.MaxSubmitsReachedText") 26 } 27 else 28 { 29 int.TryParse(GetGlobalValue("Global:Page.ID"), out int pageId); 30 var action = WinActionHelper.GetActionItemByPageId(pageId); 31 var onlyOne = false; 32 if (action != null && action.SystemName.Equals(Huuskes.Items.Constants.ItemConstants.Page_HuuskesWinActionPage)) 33 { 34 onlyOne = ItemHelper.GetItemValue<bool>(action, "OnlyOneParticipationPerEmailAddress"); 35 } 36 var sumbitButtonId = ""; 37 38 var participantDisplay = ItemHelper.GetItemValue<string>(action, "ParticipantDisplay"); 39 var customField1 = ItemHelper.GetItemValue<string>(action, "ParticipantDisplayCustom1"); 40 var customField2 = ItemHelper.GetItemValue<string>(action, "ParticipantDisplayCustom2"); 41 var hasCustomDisplayFields = !string.IsNullOrWhiteSpace(participantDisplay) && 42 participantDisplay.Equals(Huuskes.Items.Constants.ItemConstants.Option_WinActionParticipantDisplay_Custom) && 43 (!string.IsNullOrWhiteSpace(customField1) || !string.IsNullOrWhiteSpace(customField2)); 44 45 46 <form method="post" action="@formAction" enctype="multipart/form-data" class="@formCssClass" id="@formId" onsubmit="@formOnSubmit"> 47 @formSystemFields 48 @foreach (LoopItem field in GetLoop("Fields")) 49 { 50 int fieldId = field.GetInteger("Field.ID"); 51 string fieldHtmlId = field.GetString("Field.HtmlId"); 52 string fieldName = Translate(string.Format("Form_{0}", field.GetString("Field.Name").Replace(" ", "_")), field.GetString("Field.Name")); 53 string fieldControl = field.GetString("Field.Control"); 54 string fieldType = field.GetString("Field.Type"); 55 bool showInline = showInlineFieldTypes.Contains(fieldType); 56 bool fieldIsButton = field.GetBoolean("Field.IsButton"); 57 bool fieldIsOther = field.GetBoolean("Field.IsOther"); 58 bool fieldRequired = field.GetBoolean("Field.Required"); 59 string cssClass = field.GetString("Field.CssClass"); 60 bool isCustomField = field.GetString("Field.SystemName").Equals("CustomField1") || field.GetString("Field.SystemName").Equals("CustomField2"); 61 bool showCustomField = hasCustomDisplayFields && 62 ( 63 (field.GetString("Field.SystemName").Equals("CustomField1") && !string.IsNullOrWhiteSpace(customField1)) || 64 (field.GetString("Field.SystemName").Equals("CustomField2") && !string.IsNullOrWhiteSpace(customField2)) 65 ); 66 67 if (fieldType == "TextInput" || 68 fieldType == "Email" || 69 fieldType == "Tel" || 70 fieldType == "Date") 71 { 72 73 var inputType = fieldType.Equals("TextInput") ? "text" : fieldType.ToLower(); 74 75 var textInputPlaceholderText = field.GetString("Field.Placeholder"); 76 if (isCustomField) 77 { 78 if (field.GetString("Field.SystemName").Equals("CustomField1")) 79 { 80 textInputPlaceholderText = customField1; 81 } 82 if (field.GetString("Field.SystemName").Equals("CustomField2")) 83 { 84 textInputPlaceholderText = customField2; 85 } 86 87 } 88 if (string.IsNullOrWhiteSpace(textInputPlaceholderText) && !formLabelOverField && !showInline) 89 { 90 textInputPlaceholderText = field.GetString("Field.Name"); 91 } 92 if (!string.IsNullOrWhiteSpace(textInputPlaceholderText)) 93 { 94 textInputPlaceholderText = textInputPlaceholderText.HtmlRemove().Replace(" ", "_"); 95 } 96 textInputPlaceholderText = Translate(string.Format("Form_Label_{0}", textInputPlaceholderText), textInputPlaceholderText); 97 if ((fieldRequired || isCustomField) && !formLabelOverField && !showInline) 98 { 99 textInputPlaceholderText += "*"; 100 } 101 102 var textInputPlaceholder = !string.IsNullOrWhiteSpace(textInputPlaceholderText) ? string.Format(" placeholder=\"{0}\"", textInputPlaceholderText) : ""; 103 var textInputRequired = fieldRequired || isCustomField ? " required=\"required\"" : ""; 104 105 var maxLength = "50"; 106 if (fieldType == "Email") 107 { 108 maxLength = "225"; 109 } 110 111 string textInput = string.Format("<input type=\"{3}\" id=\"{0}\" name=\"{0}\"{1} {2} class=\"{4}\" maxlength=\"{5}\" />", 112 field.GetString("Field.SystemName"), 113 textInputPlaceholder, 114 textInputRequired, 115 inputType, 116 cssClass, 117 maxLength); 118 fieldControl = textInput; 119 } 120 else if (fieldType == "Select") // take option texts from translations 121 { 122 var selectRequired = field.GetBoolean("Field.Required") ? " required=\"required\"" : ""; 123 string select = string.Format("<div class=\"select-wrapper\"><span class=\"caret\"></span><select id=\"{0}\" name=\"{0}\"{1}>", 124 fieldHtmlId, 125 selectRequired); 126 select += string.Format("<option value=\"\">{0}</option>", fieldName); 127 foreach (LoopItem option in field.GetLoop("Options")) 128 { 129 select += string.Format("<option value=\"{0}\">{1}</option>", 130 option.GetString("Option.Value"), 131 Translate(string.Format("Form_WinActionOption_{0}", option.GetString("Option.Value")), option.GetString("Option.Text"))); 132 } 133 select += "</select></div>"; 134 fieldControl = select; 135 } 136 else if (fieldType == "Textarea") // take placeholder text from translations 137 { 138 var textAreaPlaceholderText = field.GetString("Field.Placeholder"); 139 if (string.IsNullOrWhiteSpace(textAreaPlaceholderText) && !formLabelOverField && !showInline) 140 { 141 textAreaPlaceholderText = field.GetString("Field.Name"); 142 } 143 if (!string.IsNullOrWhiteSpace(textAreaPlaceholderText)) 144 { 145 textAreaPlaceholderText = textAreaPlaceholderText.HtmlRemove().Replace(" ", "_"); 146 } 147 textAreaPlaceholderText = Translate(string.Format("Form_Label_{0}", textAreaPlaceholderText), field.GetString("Field.Placeholder")); 148 if (field.GetBoolean("Field.Required") && !formLabelOverField && !showInline) 149 { 150 textAreaPlaceholderText += "*"; 151 } 152 153 var textAreaPlaceholder = !string.IsNullOrWhiteSpace(textAreaPlaceholderText) ? string.Format(" placeholder=\"{0}\"", textAreaPlaceholderText) : ""; 154 var textAreaRequired = field.GetBoolean("Field.Required") ? " required=\"required\"" : ""; 155 string textArea = string.Format("<textarea rows=\"0\" id=\"{0}\" name=\"{0}\"{1}{2}></textarea>", 156 fieldHtmlId, 157 textAreaPlaceholder, 158 textAreaRequired); 159 fieldControl = textArea; 160 } 161 else if (fieldType == "File") 162 { 163 var fileSelectorRequired = field.GetBoolean("Field.Required") ? " required=\"required\"" : ""; 164 string fileSelectorButtonText = Translate(string.Format("Form_FileButton_{0}", field.GetString("Field.Name").HtmlRemove().Replace(" ", "")), field.GetString("Field.Name")); 165 string fileSelector = string.Format("<label class=\"custom-file-upload\"><input type=\"file\" id=\"{0}\" name=\"{0}\" multiple=\"\" accept=\".jpg,.jpeg,.png,.gif\" {2} />{1}</label>", fieldHtmlId, fileSelectorButtonText, fileSelectorRequired); 166 fieldControl = fileSelector; 167 } 168 string fieldDescription = field.GetString("Field.Description"); 169 if (!string.IsNullOrWhiteSpace(fieldDescription)) 170 { 171 fieldDescription = string.Format("<br /><span class=\"description\">{0}</span>", fieldDescription); 172 } 173 174 string requiredImage = string.Empty; 175 if (fieldRequired && !string.IsNullOrEmpty(formLabelRequired)) 176 { 177 requiredImage = formLabelRequired.Contains(".") ? string.Format("<img src=\"/Files/images/{0}\">", formLabelRequired) : formLabelRequired; 178 } 179 180 // DEFINE LABEL AND CONTROLCLASS 181 var labelClass = formLabelOverField ? "label label-clear" : "label"; 182 var controlClass = formLabelOverField ? "control control-clear" : "control"; 183 if (showInline) 184 { 185 labelClass += " show-inline"; 186 controlClass += " show-inline"; 187 } 188 189 if (formLabelBold) 190 { 191 labelClass += " text-bold"; 192 } 193 194 //HIDDEN INPUTS 195 if (fieldType.Equals("Hidden", StringComparison.InvariantCultureIgnoreCase)) 196 { 197 <text>@fieldControl</text> 198 } // EMPTY FIELD TO ALIGN FIELD PROPERLY 199 else if (field.GetString("Field.Name") == "Spacer") 200 { 201 <div class="spacer hidden-phone"></div> 202 } // CHECKBOX 203 else if (fieldType == "CheckBox") 204 { 205 string fieldActivityDescription = field.GetString("Field.Activity.Description"); 206 if (!string.IsNullOrEmpty(fieldActivityDescription)) 207 { 208 // CREATE CONSENT LABEL 209 210 // general conditions replace 211 fieldName = Huuskes.Repository.Helpers.HtmlHelper.ReplaceTagWithLink( 212 Dynamicweb.Frontend.PageView.Current(), 213 fieldActivityDescription, 214 "{general-conditions}", 215 Translate("general-conditions", "general conditions"), 216 Huuskes.Models.Constants.StringConstants.NavigationTags.GeneralConditions, 217 "_blank" 218 ); 219 220 // job applicants general conditions replace 221 fieldName = Huuskes.Repository.Helpers.HtmlHelper.ReplaceTagWithLink( 222 Dynamicweb.Frontend.PageView.Current(), 223 fieldActivityDescription, 224 "{privacy-statement}", 225 Translate("privacy-statement", "privacy-statement"), 226 Huuskes.Models.Constants.StringConstants.NavigationTags.PrivacyStatement, 227 "_blank" 228 ); 229 230 // job applicants general conditions replace 231 fieldName = Huuskes.Repository.Helpers.HtmlHelper.ReplaceTagWithLink( 232 Dynamicweb.Frontend.PageView.Current(), 233 fieldActivityDescription, 234 "{privacy-statement-for-applications}", 235 Translate("privacy-statement-for-applications", "privacy-statement for applications"), 236 Huuskes.Models.Constants.StringConstants.NavigationTags.PrivacyStatementForApplications, 237 "_blank" 238 ); 239 240 // remove surrounding paragraph tags 241 fieldName = fieldName.Replace("<p>", "").Replace("</p>", ""); 242 243 } else if (fieldName.Equals("AgreedWithConditions")) { 244 fieldName = "Ik ga akkoord met de actievoorwaarden zoals beschreven in de algemene voorwaarden van Huuskes.nl"; 245 var actionConditionsText = ItemHelper.GetItemValue<string>(action, "ActionConditionsText"); 246 if (!string.IsNullOrWhiteSpace(actionConditionsText)) { 247 fieldName = actionConditionsText; 248 } 249 if (fieldName.Contains("{action-conditions}")) { 250 var actionConditionsLink = ItemHelper.GetItemValue<string>(action, "ActionConditionsLink"); 251 if (!string.IsNullOrWhiteSpace(actionConditionsLink)) { 252 253 var conditionsLink = $"<a href=\"{actionConditionsLink}\" target=\"_blank\">{Translate("WinAction_ActionConditions", "action conditions")}</a>"; 254 fieldName = fieldName.Replace("{action-conditions}", conditionsLink); 255 } 256 } 257 258 } 259 <div class="form-group flex flex-align-center checkbox"> 260 @fieldControl 261 <label for="@fieldHtmlId"> 262 <span class="circle"></span> 263 <span class="flex flex-wrap flex-align-center"> 264 265 @fieldName @(fieldRequired ? "*" : "") 266 </span> 267 </label> 268 </div> 269 } // RADIO AND CHECKBOXLIST 270 else if (fieldType == "Radio" || fieldType == "CheckBoxList") 271 { 272 var listType = fieldType == "CheckBoxList" ? "checkbox" : "radio"; 273 <div class="form-group @fieldType.ToLower()"> 274 <label for="@fieldHtmlId"> 275 <p>@fieldName @(fieldRequired ? "*" : "")</p> 276 </label> 277 @foreach (LoopItem option in field.GetLoop("Options")) 278 { 279 var inputId = string.Concat(fieldHtmlId, option.GetInteger("Option.ID")); 280 <div class="checkbox flex"> 281 <input type="@listType" 282 id="@inputId" 283 name="@fieldHtmlId" 284 value="@option.GetString("Option.Value")" 285 @(fieldRequired && fieldType == "Radio" && option.Index == 1 ? "required " : "") 286 @(option.GetBoolean("Option.DefaultSelected") ? "checked " : "") /> 287 <label for="@inputId"> 288 <span class="circle"></span> 289 @Translate(string.Format("FormsForEditor_{0}", option.GetString("Option.Text")), option.GetString("Option.Text")) 290 </label> 291 </div> 292 } 293 </div> 294 } 295 else if (fieldType == "Submit") // SUBMIT 296 { 297 sumbitButtonId = $"VIS_{fieldHtmlId}"; 298 <div class="form-group @fieldType.ToLower()"> 299 <div class="@labelClass"></div> 300 <div class="@controlClass"> 301 <input type="submit" id="@fieldHtmlId" name="@fieldHtmlId" value="@fieldName" class="hidden"> 302 <input type="button" id="@sumbitButtonId" name="@sumbitButtonId" value="@fieldName" data-text="@fieldName" class="button"> 303 </div> 304 </div> 305 } // ALL OTHER INPUTS 306 else 307 { 308 if (!isCustomField || showCustomField) { 309 <div class="form-group @fieldType.ToLower()"> 310 <div class="@labelClass"> 311 @if (!fieldIsButton && !fieldIsOther) 312 { 313 <label for="@fieldHtmlId" class="theme-color">@fieldName @requiredImage</label> 314 } 315 else if (fieldIsOther) 316 { 317 @fieldName 318 } 319 </div> 320 <div class="@controlClass">@fieldControl @fieldDescription</div> 321 </div> 322 } 323 324 } 325 } 326 </form> 327 328 @SnippetStart("JavaScriptBottom") 329 <script> 330 $(document).ready(function () { 331 332 var submittingParticipation = false; 333 var formCssClass = ".@formCssClass.Replace(" ", ".")"; 334 335 // init 336 WinAction.FormInit(formCssClass); 337 338 // fill hidden fields 339 WinAction.FillHiddenFields('@GetGlobalValue("Global:Page.ID")','@Guid.NewGuid().ToString()', '@pageView.Area.Culture'); 340 341 // on change validate 342 $("input[type=text], input[type=email], input[type=tel], input[type=date], input[type=file], textarea", formCssClass).on("keyup", function () { 343 WinAction.FormValidate(formCssClass); 344 }); 345 $("input[type=radio], input[type=checkbox], select, input[type=text], input[type=email], input[type=tel], input[type=date], input[type=file], textarea", formCssClass).on("change", function () { 346 WinAction.FormValidate(formCssClass); 347 }); 348 349 // Init datepicker 350 $(".huuskesDatepicker").datepicker({ 351 dateFormat: "dd-mm-yy" 352 }); 353 354 // Fix Dates 355 if ($(".hasDatepicker", formCssClass)[0]) { 356 Form.ShowDatePlaceholder(formCssClass); 357 } 358 359 // Only numbers in telephone fields 360 $("input[type=tel]").numeric(); 361 362 @if (onlyOne) { 363 var pageService = new Dynamicweb.Content.PageService(); 364 var participationsFeedPage = pageService.GetPageByNavigationTag(Dynamicweb.Frontend.PageView.Current().AreaID, Huuskes.Models.Constants.StringConstants.NavigationTags.WinActionParticipationsFeed); 365 var participationsFeedPageId = participationsFeedPage?.ID ?? 0; 366 <text> 367 $("#@sumbitButtonId").off("click").on("click", function (e) { 368 if (!submittingParticipation) { 369 submittingParticipation = true; 370 var formId = '@formId'; 371 var participationsFeedPageId = '@participationsFeedPageId'; 372 var actionPageId = '@GetGlobalValue("Global:Page.ID")'; 373 var emailAddress = $("input[type=email]", "#" + formId).val(); 374 var feedPageUrl = "/Default.aspx?ID=" + participationsFeedPageId + "&action=" + actionPageId + "&emailaddress=" + emailAddress; 375 $.getJSON(feedPageUrl) 376 .done(function (result, status, metaData) { 377 if (result !== null && result.length > 0) { 378 alert('@Translate("WinAction_MultipleParticipationsError", "Email already exist")'); 379 } else { 380 $("#" + formId).submit(); 381 } 382 }).fail(function (jqxhr, textStatus, error) { 383 var err = textStatus + ", " + error; 384 console.error("Submit form failed: " + err); 385 }).always(function () { 386 submittingParticipation = false; 387 }); 388 } 389 }); 390 </text> 391 } 392 393 }); 394 </script> 395 @SnippetEnd("JavaScriptBottom") 396 } 397 }