Formoj for Laravel: a package to build and share custom forms

Aka Tiny Google Forms without the drawbacks

Philippe Lonchampt
code16
3 min readMar 9, 2019

--

Photo by rawpixel on Unsplash

One of our clients, at Code 16, needed to display various forms to their visitors for subscriptions, registration, … They wanted the forms to be embedded in their website, and our first answer was of course to use Google Form.

But they were quite unhappy with it, mainly because the graphical integration is far from ideal, but also for less obvious reasons: the form administration is separated from their admin console, the form creation could be complex (since they didn’t need so many options), they need for that a dedicated and shared Google account, and finally (last but not least) they want to have control of the way their customers’s data is handled and stored.

That’s why we finally decide to develop a much smaller but easier to integrate version of Google Form. We call it Formoj for Laravel.

Yes! It even has a logo (or kind of).

What is Formoj?

Formoj is an open source package, for Laravel 5.8+, which provides:

  • Front-end code (Vue.js based)to display and interact with forms, sections, textfields, select fields and so on.
  • Back-end code (Laravel) with API endpoints, models, migrations, jobs, notifications, …
  • And an optional administration tool, based on Sharp for Laravel, to manage all this.

The main features of Formoj are:

  • Embed forms with text fields, multi rows texts, selects and multi choice selects, grouped in optional sections (cutting the form into previous / next panels), with a fully configurable styling.
  • Optional publication dates (from and/or to).
  • Administrator notification strategies (on each answer, or grouped by day).
  • And answers export to XLS file.

How it integrates in a Laravel project?

It’s a package, so you install it (follow the documentation for that), and then you can either use Sharp for Laravel to manage forms, or use your own administration code; models are regular Eloquent, with a dedicated and fluent API to create fields:

$form = Form::find($id);$section = $form->createSection("My section");

$text = $section->newTextField("text")
->setRequired()
->setHelpText("help")
->setMaxLength(50)
->create();

And next, to embed a form in your pages, well:

<formoj form-id="1"></formoj>

And that’s it! Here’s a screenshot of a form with he default style:

Mmm, it’s in frenglish. Sorry for that.

And another one, but this time integrated in a real website:

French and Latin, this time… The Formoj form itself is the panel bordered in gray.

How to deal with answers?

Answers are stored in a dedicated table, and Formoj comes with a job to create an Excel version of the full list. Details are in the documentation, but here’s some sudo code to demonstrate the feature:

$form = Form::find($id);$filename = uniqid("answers_");// Create an XLS file named $filename with all $form answers:
ExportAnswersToXls::dispatch($form, $filename);

The Formoj config file allows to choose export base path and disk. And once again, if you choose to use Sharp, you’ll have a built-in Command to handle this export for you.

That’s it for this quick presentation of Formoj. You can find more information on Github, and reach me via twitter.

--

--

Philippe Lonchampt
code16
Editor for

Developer and founder of Code 16, maintainer of Laravel Sharp.