Forms plugin for Kirby 3

Just published a plugin to make it easier to create HTML forms without going blurry eyed at a wall of PHP & HTML. Contains a number of functions to generate inputs, labels, select elements, and error messages.

6 Likes

hi there,

whats the use case for this plugin? i just sneaked into the code and i think this is a bunch of helper functions within other helper functions.

what about simply writing html? isnt that much better for performance reasons?

you dont have to answer, this is just my point of view. :zipper_mouth_face:

@kaltschnitt It is much harder to read HTML mixed with PHP. On long forms it can get really messy. When using an html framework, a single field is often 7 or 8 lines of code with the label and error message. This plugin lets you do it in a single line.

Additionally, because this uses functions, you can offload complex logic to the controller and get HTML returned instead of cluttering up your template.

For example a select field:

<?= select('colors', 'colorSelection', 'input-class', null, ['Red' => 'red', 'Green' => 'green', 'Blue' => 'blue'], true, 'Blue') ?>

This creates all the option elements from an array. It would dead easy to wire this into a structure field now, since you can just grab the structure field in the controller, turn it into an array and pass it to the snippet. The plugin deals with turning that array into a an set of HTML option tags, so you dont have to worry about it. Just feed it an at associative array.

ok, good example. the select field is the most complex field. this makes absolutely sense.

but for the other ones iā€˜d go for the kirby html helper class to generate the tags wrapped up in a snippet if u use some advanced styling or frameworks you mentioned. there you can pass as much data as you like.

Well thats what the functions do, they are just in conveinent little helpers. They all use HTML::tag to render the html to the template.

Not eveyone knows how to make this stuff - this is for them :slight_smile:

1 Like