public Form ConstructFormDefinition(FormCollection form_) { Form dynamicFormDefinition = null; if (form_ != null) { dynamicFormDefinition = new Form(); dynamicFormDefinition.FormName = form_["FormName"]; dynamicFormDefinition.IsActive = Convert.ToBoolean(form_["Active"]); dynamicFormDefinition.SiteId = Guid.Parse(form_["SiteId"]); for (int iCounter = 1; iCounter <= 50; iCounter++) { //Check whether target field is present for this iteration, if not present consider ending the loop if (form_["fieldnameqrow" + iCounter.ToString()] != null) { switch (Utility.GetFormFieldValue(form_, "fieldtypeqrow" + iCounter.ToString())) { case "TextBox": TextBox field = new TextBox(); field.ResponseTitle = Utility.GetFormFieldValue(form_, "fieldnameqrow" + iCounter.ToString()).Replace(" ", "-"); dynamicFormDefinition.AddFields(field); break; case "TextArea": TextArea textArea = new TextArea(); textArea.ResponseTitle = Utility.GetFormFieldValue(form_, "fieldnameqrow" + iCounter.ToString()).Replace(" ", "-"); dynamicFormDefinition.AddFields(textArea); break; case "CheckBox": CheckBox checkBox = new CheckBox(); checkBox.ResponseTitle = Utility.GetFormFieldValue(form_, "fieldnameqrow" + iCounter.ToString()).Replace(" ", "-"); dynamicFormDefinition.AddFields(checkBox); break; case "CheckBoxList": CheckBoxList checkBoxList = new CheckBoxList(); checkBoxList.ResponseTitle = Utility.GetFormFieldValue(form_, "fieldnameqrow" + iCounter.ToString()).Replace(" ", "-"); dynamicFormDefinition.AddFields(checkBoxList); break; case "ListBox": Select select = new Select(); select.ResponseTitle = Utility.GetFormFieldValue(form_, "fieldnameqrow" + iCounter.ToString()).Replace(" ", "-"); dynamicFormDefinition.AddFields(select); break; case "RadioBoxList": RadioList radioList = new RadioList(); radioList.ResponseTitle = Utility.GetFormFieldValue(form_, "fieldnameqrow" + iCounter.ToString()).Replace(" ", "-"); dynamicFormDefinition.AddFields(radioList); break; } } } } return dynamicFormDefinition; }
void Demo3SetKeys(Form form) { int key = 1; foreach (var field in form.InputFields) { field.Key = key++.ToString(); } }
public ActionResult Demo1(Form form) { // ^ // no need to retrieve the form object from anywhere // just use a parameter on the Action method that we are posting to if (form.Validate()) //input is valid return View("Responses", form); // input is not valid return View("Demo", form); }