How are you making forms with Sage 9?

sage9

#1

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


#2

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


#3

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.


#4

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)


#5

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.


#6

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.


#7

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.


#8

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.


#9

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!


#10

I often use Caldera Forms:


#11

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