I'm working on a plugin which submits data via a form from a custom admin page. This is a simplified version of my form:
<form action="<?php echo plugin_dir_path(); ?>/process.php" method="post">
<input type="text" name="keyName">
<input type="submit" value="Update">
</form>
The form is inside my main php file for the plugin, so it has access to all the WordPress functions like the plugin_dir_path() I called above.
However when the user clicks the "submit" button, and the $_POST variable is submitted to the "process.php" script, I lose access to all the WordPress functions in that process script.
I searched how to add WordPress functions into external scripts and I saw this question: How can I call WordPress core functions in external scripts?
The answer provided is that I include this line of code at the top of my processing script:
require_once("wp-load.php");
However when I do the "wp-load.php" is appended to the end of the current url which results in a 404 type error. I can't use the "get_site_directory()" function to point to the main WordPress install directory because it's a WordPress function.
How can I make this work? Is there an action hook I should be using to submit the form vs my own custom submit button?