• I have a local install of WP and never used it before so I am having a bit of a problem trying to do what I want to do. If anyone can offer some suggestions on what I should look into that would be great.

    What I want to do.
    Setup a web page that has a few text input boxes and a button. Do I need a plugin to add these?
    Button runs some code and uses input from text boxes and an API. Is there somewhere within the wp-admin I can do this or would it also be part of a plugin?

    The code needs to do the following.
    Send and get information using an API on remote server.
    Run some if statements to decide what API call to do and what message/page to send back to user.

    I have found a PHP API class someone has made to help interact with the API easier. Not sure if it is usable with a WP site. https://github.com/Art-of-WiFi/UniFi-API-client

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can put whatever HTML you want in your page/post, including input boxes and buttons. But in order to process the form submission, you need to have some code to run, looking for that form submission, unless it’s all done in javascript. Even if it’s all JS, you need to get that JS into the page.
    Since you have a PHP class that you want to use, I’ll assume it’s not javascript.

    You need to write a plugin to generate the form HTML (and prefill with values already input, or not). If it’s for frontend pages, this is typically done with a shortcode. With the new editor, you could make a custom block.
    The plugin would check for the $_POST variable with your unique value for the form submission. (It needs a hidden field nonce also.) It would call the API based on the values, and either repopulate the form or put the API results there (or both).
    So, it’s two main parts. The shortcode handler does the form. The form handler calls the API.

    Thread Starter spy3

    (@spy3)

    Hi

    Thanks for that information. I read over an example for using the nonce bit but not sure I get it yet. My understand was I need to do a JQuery for the front end and then it links with AJAX to the php server side. Will continue to look into that.

    If you have used this before do you know if I can do with the “Form Maker” plugin? It has lots of features I already want. https://ww.wp.xz.cn/plugins/form-maker/

    I have discovered today when a device is sent to the server it comes with a $_POST query. I would like to capture the MAC address from this to use later and maybe other things.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Button to run custom PHP class for an API’ is closed to new replies.