0

I want to create my own code for displaying and editing a logged in user's profile.

For that I want to create a form inside a Wordpress page and pre-populate the form fields with data before the page is displayed. I want to do this independently of any plugin providing form widgets. This raises the following questions for me:

  1. Is there a general form and form data handling mechanism in Wordpress that I can facilitate for this, like e.g. Wordpress has a form object containing a "field" or data object for each of the form's fields, allowing me to access the form(s) on a page?

  2. I actually wouldn't even need a form object. Instead, I could just place a couple of input fields on the page. How would I access these in some php function?

  3. How would I access the forms (is there e.g. a Wordpress function receiving the form name and returning me a form object?)

  4. How would I intercept loading of the page containing the form(s) (or any page, that is) before it gets rendered, but after the form object is instantiated/initialized?

As I said, I am not looking for a particular form implementation by e.g. some plugin, but whether there is a general underlying mechanism, which might eventually be utilized by such plugins, I could facilitate.

1 Answer 1

1

Is there a general form and form data handling mechanism in Wordpress that I can facilitate for this, like e.g. Wordpress has a form object containing a "field" or data object for each of the form's fields, allowing me to access the form(s) on a page?

No, there is not.

I actually wouldn't even need a form object. Instead, I could just place a couple of input fields on the page. How would I access these in some php function?

The same way any other PHP/HTML application would. WordPress does not provide a form API.

How would I access the forms (is there e.g. a Wordpress function receiving the form name and returning me a form object?)

How would I intercept loading of the page containing the form(s) (or any page, that is) before it gets rendered, but after the form object is instantiated/initialized?

You don't, there are no form APIs or objects in WordPress, that is not a feature WordPress implements.

As I said, I am not looking for a particular form implementation by e.g. some plugin, but whether there is a general underlying mechanism, which might eventually be utilized by such plugins, I could facilitate.

No such mechanism exists. Each form plugin builds their form system from scratch. Some use custom tables to store the data, some use custom post types, but there is no generic system that sits underneath them. You would have to build it yourself or use a 3rd party plugin/library to provide it.

2
  • I think there are Wordpress hooks you can use to make your function called when a Wordpress page is invoked. I am using such a hook to do some redirections on my website. Jun 17, 2021 at 6:19
  • 1
    I do not understand what that has to do with this question or my answer. If you want to modify, create, or populate forms, that is not possible without a form plugin, there is no general way to do it, and no method that works for all form plugins. WordPress has no concept of forms. Each form plugin requires a unique specific solution that will only work for that plugin. You would have to build it from scratch yourself. The interface/system/API/framework you are asking about does not exist
    – Tom J Nowell
    Jun 17, 2021 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.