When CGI ruled the Web, CGI::FormBuilder was one of the good ways of keeping the form DRY by having the same code generate the form and validate passed parameters once it is submitted.
I am writing a small Dancer2 web application which needs to have a form. Originally I had considered generating and validating the form from the same description, but then I realised that such generated form would be limited in terms of layout I want to present to the user. For example, most of the fields follow a simple template:
But a few fields are more complicated, for example, there is two fields per one item description:<p> <label for="[% id %]">[% name %] = </label> <input name="[% id %]" placeholder="[% placeholder %]" type="text" id="[% id %]" [% required %] pattern="[% regex %]" > <label for="[% id %]">[% units %]</label> </p>
What are the best practices for form design in 2019? Should I generate the form? (if so, how should I structure the form description if I have to account for various deviations from the template?) Should I keep the form and the form code separate, but complain loudly in case I receive an unexpected parameter? (my original goal in pursuing DRY is preventing typos and facilitating later updates)<p> <label for="lowwl">Wavelength:</label> <input name="lowwl" placeholder="400" type="text" id="lowwl" pattern="(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?" > <label> - </label> <input name="upwl" placeholder="600" type="text" id="upwl" pattern="(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?" > <label for="upwl">nm</label> </p>
In reply to Form generation and validation by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |