How to create a widget that has a submit form in the front end

I see three main ways to handle front-end form submissions in a widget:

  • A regular form that submits via POST and reloads the whole page. Easy to understand, easy to create, but not a nice user experience.
  • Load your widget in a iframe, so that a form submission only reloads the iframe. Some external providers do this (eg. Google Calendar), but it may be harder to style the widget.
  • Do the form submission via Ajax (with a regular form as a fallback?). This is probably the nicest option, but requires some work on your side. I once tried to give a high-level overview of Ajax in WordPress, maybe that is a good place to start.

If you leave a comment on this answer which way you prefer, I could give you more details.

Leave a Comment