A semi-dynamic form builder to ease the pain developing large forms
A TV casting application form with admin system.
A simple TV casting application form with admin system allowing staff to search and track the progress of the applicants, hosted on AWS infrastructure.
a semi-dynamic form builder was used to quickly define forms and render them
As there were a number of forms all slightly different, I developed a semi-dynamic form builder. The form definition was a simple C# class decorated with attributes.
public class CastingForm
{
[Required]
[Dropdown()]
public string Age { get; set; }
[Required()]
[Textbox()]
[Display(Name = "My email address")]
[IgnorecaseRegularExpression(@"^[^@]+@[^@]+\.[^@]+$", true, ErrorMessage = "You must enter a valid email address")]
public string Email { get; set; }
[IgnorecaseRegularExpression(@"^.*\.(jpg|jpeg|png|gif)$", true, ErrorMessage = "Please make sure your image is either a jpg, gif or png")]
[Required]
[MaxFileSizeAttribute(1048576, ErrorMessage = "Please make sure your image is under 1MB")]
[FileUpload]
[Display(Name = "Upload a photo. (max 1MB. Jpgs, pngs, and gifs only)")]
[Ignore]
public HttpPostedFileBase Photo { get; set; }
...
}
The form is then rendered as HTML via a simple, generic piece of Razor:
foreach (var question in Html.GetQuestions(Model))
{
<div class="question">
<div class="question-text">
@Html.RenderQuestion(question)
@if (!String.IsNullOrWhiteSpace(question.SupportingText))
{
<div class="supporting-text">@Html.Raw(question.SupportingText)</div>
}
</div>
<div class="answer @question.Id">
@Html.RenderAnswer(question)
</div>
</div>
}
I'm working on releasing the form builder as a separate piece of Open Source Software.
Get in touch to talk about your project or just ask me a question.