Re: 'Form Builder'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 16, 2016 at 10:39 AM, Lester Caine <lester@xxxxxxxxxxx> wrote:
>
>
> So is there something I've missed that may be worth considering even at
> this stage of things?
>

I'm in the minority, but I tend to craft DSL's to maintain flexibility for
use cases such as HTML forms.

For example, I've coded a recursive descent parser implemented with a
Parsing Expression Grammar (PEG.) The short overview is that I embed a DSL
for forms directly in my HTML files:

<!DOCTYPE html>
<html>
<head>
  <title>Example page with embedded DSL</title>
</head>
<body>
  <h1>Example page with embedded DSL</h1>
<!--qform:o-->
- method post

text
- name name
- maxlength 30
- required

email
- name email

textarea
- name my-message

submit
- value Send message
<!--qform:c-->
</body>
<html>

Then, I have a preprocessor that parses my directory of files and outputs
the form code in whatever format I need across the entire project:

<!DOCTYPE html>
<html>
<head>
  <title>Example page with embedded DSL</title>
</head>
<body>
  <h1>Example page with embedded DSL</h1>
<form method="post">
  <div class="form-group">
    <label for="name">Name</label>
    <input type="text" name="name" maxlength="30" required="required"
id="name" />
  </div>
  <div class="form-group">
    <label for="email">Email</label>
    <input type="email" name="email" id="email" />
  </div>
  <div class="form-group">
    <label for="my-message">My-message</label>
    <textarea name="my-message" id="my-message"></textarea>
  </div>
  <div class="form-group">
    <input type="submit" name="field4" id="field4" value="Send message" />
  </div>
</form>
</body>
<html>

The value for me is two-fold:
- I only enter the minimum information required to declare my forms.
- Updating the forms sitewide or across multiple projects (updating to new
version of bootstrap, changing HTML implementation, etc.) merely requires
making changes in one location in the parser.

You can see an example implementation of this approach in Go at my Github
account:
https://github.com/AdamJonR/polyglot

Now, to be clear, this is not a solution embraced by the masses. However,
after using this approach for a couple years, I love it and don't plan on
using anything else.

Adam

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux