Settings API form – submit with AJAX

I just tested your code, I guess the ajaxurl in your javascript is wrong, it must be: <?php echo admin_url( ‘options.php’ ); ?> This is the code I have tested. class TestAjaxSettingsAPI { public function __construct() { add_action( ‘admin_menu’, array( $this, ‘agy_admin_menu’ ) ); add_action( ‘admin_init’, array( $this, ‘agy_register_settings’) ); } public function agy_admin_menu() { … Read more

How a HTML form can trigger a PHP function?

It sounds like you want an AJAX request of some sort. In your functions.php file, enqueue some JavaScript to handle the form. wp_register_script( ‘my-scripts’, get_stylesheet_directory_uri() . ‘/[path to your scripts]/myscripts.js’, array( ‘jquery’ ), ‘1.0’, true ); See this link for reference. Right under that, add a JavaScript variable for your AJAX URL. wp_localize_script( ‘my-scripts’, ‘data’, … Read more