How to organize my code for a custom form in WordPress?

We are in the process of making a new version of our website (currently developed in-house in PHP) with WordPress and the WPML plugin.

Our current site contains some forms, and one of them is very specialized:
it is used to make free trials of our web application. It uses some external libraries to perform its duty (connection to MSSQL, send email, register tracking events with a REST service, etc.).

Read More

Since I am pretty new to WordPress, I don’t really know how I should organize my code and libraries to display the form and handle submit. I have some experience with a MVC framework (CodeIgniter) and I like the way things are organized.

From my first research, I could create a custom template and code the form directly in it (and include my libraries there too), and also handle the POST directly in the template too (which is, from my perspective, not that well organized: “controller” code in the “view”).

Maybe I should also develop a plugin just for that form, I’m not really sure.

What are the recommendations to create a custom form which uses a couple libraries like what I am trying to achieve ?

Related posts

Leave a Reply

1 comment

  1. The feature you are describing sounds exactly like the candidate for a plugin. Anything that changes or adds a feature to WordPress should be a plugin, your theme files should be reserved for how the site looks.

    Making it a plugin separates your view concerns (your theme) from your functionality concerns (this plugin). You will be able to update or change your theme without having to port/adapt/rewrite a bunch of code that’s mixed into the theme, and your code will be organized much better.

    Also see Does My Functionality Belong in a WordPress Plugin or Theme? on SitePoint for another take on this.