How are you making forms with Sage 9?

I have used some of the form plugins such as Ninja forms etc… however I feel quite limited by these form builders. I like to be able to create the markup for my form elements instead of it being generated by a drag and drop plugin.

I need to post the form to the controller layer and then from one of the controllers within Sage I need to manipulate the data before submitting it to the Wordpress DB.

Is there a good plugin out there for developers that would allow me to post to the controller layer and manipulate the data before submitting the form:
57

I’ve came from a Laravel background and used it’s form template engine, just wondering what the most popular solution in Sage 9 and Wordpress is?

Thanks

I use Formidable when I can, and Gravity Forms when I need to integrate with something (like SalesForce) that Formidable struggles with.

Pretty much always Gravity Forms here, unless it’s a really simple site. I use the Jetpack form on my own blog, but everywhere else I use Gravity Forms.

Also bear in mind that the controllers in sage work differently than the controllers in Laravel. They do not intercept requests, they’re just limited to expose variables and separate general logic from your templates. Validation and such has to be done elsewhere (admin-ajax actions or via hooks before-update)

Thanks guys, I tried using Gravity Forms but I was told that I can’t develop forms within my theme using my own markup which sucks. The form builder doesn’t allow me to create bespoke forms, still quite a good plugin for basic forms mind.

I haven’t tried this yet, but Gravity Forms has a relatively robust API, so in theory you could craft your own forms however you want, and then submit that data to Gravity Forms through their API.

Usually when I need forms I just end up using Gravity Forms, even though customizing forms can be a huge pain. The backend stuff it provides for you is super useful, and most of the time I’m willing to deal with the front-end frustration because of all the other stuff it just does for you.

2 Likes

I usually create my own forms, either in blade or via a vue component. Within your theme you can do anything you like, there are no limitations! I rarely use plugins, cause personally, for my projects I prefer to deliver a higher level of customisation which is usually not easily achievable/maintainable through plugins.

That’s definitely true. My clients’ email has proven so unreliable over the years that the entry capture of a tool like Gravity or Formidable has proven absolutely necessary.

1 Like

Very true!I usually end up creating custom post types so that I can store all entries neatly and reorganise the columns in the admin area for a quick preview. Having a custom post type also allows me to hook into the creation of the post and send notifications and such!

I often use Caldera Forms:

It’s not something they make easy, due to the complexity of the required templating, however it is 100% possible, and we do it quite commonly at my work.

You have a couple different options:

  1. Grab the gravity forms form ‘object’ (actually it’s a giant array) and dump that as JSON into your page, then use a client side library like vue to parse the field data in there to construct the form. In these instances you commonly develop to the known functionality of the form, so that you don’t need to cover all of gravityforms’s features (conditional fields etc). You can then submit the form via ajax like normal or use the API endpoint, either will work.

  2. Intercept the field render calls via filters and then replace their markup with your own. We do this option pretty commonly as it allows us to template our forms with twig (we don’t run Sage currently, but a very sage-esque starter theme of our own design). I do this if I only need to customise one field eg: radio buttons.
    Key filters are gform_field_input, gform_field_container and gform_field_input if you want to change individual fields, or to write your own twig / blade templates to work with the gravity forms form ‘object’.

  3. Final option is to grab the gravity forms ‘object’ (array) and have your twig/blade templates work with that - in this case you would need new templates for each field type you intend to use. You can remove unneeded field types as options in the form build via the 'gform_add_field_buttons' filter

The following may be useful when working with gravity forms - check gravityhelp for docs on each

		add_filter('pre_option_rg_gforms_disable_css', '__return_true');
		add_filter('gform_disable_print_form_scripts', '__return_true');
		add_filter('gform_init_scripts_footer', '__return_true');

Overall it’s a pretty configurable plugin, the API docs are pretty terrible though, good luck!

Alex

3 Likes

@bish got any example code of doing this? =)

  1. Intercept the field render calls via filters and then replace their markup with your own. We do this option pretty commonly as it allows us to template our forms with twig (we don’t run Sage currently, but a very sage-esque starter theme of our own design). I do this if I only need to customise one field eg: radio buttons.
    Key filters are gform_field_input, gform_field_container and gform_field_input if you want to change individual fields, or to write your own twig / blade templates to work with the gravity forms form ‘object’.
  2. Final option is to grab the gravity forms ‘object’ (array) and have your twig/blade templates work with that - in this case you would need new templates for each field type you intend to use. You can remove unneeded field types as options in the form build via the 'gform_add_field_buttons' filter

Six years and many websites later, I would ultimately advise against this approach. The maintenance burden is large, and with GravityForm’s new react based interface it’s harder to remove the controls that don’t do anything, leading to clients thinking the site is broken.

We haven’t found too many designs or layouts that cannot be achieved with some css tricks and the default markup, if you really need something custom I’d advise you make your own custom gravity form fields via a plugin vs heavily modifying the default ones.

3 Likes

@bish Thanks for good takeaways! Its good to know this before you invest too much time and effort into the blade approach!

haha, good to see devs still kicking in the same space, six years later.

I was going to say, there’s a lot of Gists out there full of SCSS you can import if you use Bootstrap as your base, but I’m not too sure about Tailwind since we don’t really use it.

You can also just build the form however you like and use the GFAPI::submit_form() method.