Detect users input values from any wordpress form

I’m trying to develop a wordpress plugin, I need to get users input data from any form in a specific page (not knowing its action) I come up so far with this solution which is to get values using javascript and then passing it to php:

jQuery(function ($) {
    $(document).ready(function(){
        $( "form" ).submit(function( event ) {
        if($( "form" ).valid()){
            var inputs = $( "form input" );
            var inputValues = [];
            inputs.each(function(index){
                if($(this).attr('type') !== 'submit')
                    inputValues.push($(this).val());
            });
        }
        event.preventDefault();
        });

    });
});

I tried to pass the Javascript variable inputValues to my plugin using Ajax

$.ajax({
  type: 'POST',
  url: '../wp-content/plugins/myplugin/myplugin.php',
  data: {'variable': inputValues},
   });

But I get problems with the url for some pages and I couldn’t use $_POST[‘variable’] in myplugin.php file.
Is there a way to accomplish what I’m trying to do, or do you know an alternative solution?
Thanks in advance.

Read more here: Detect users input values from any wordpress form

Leave a Reply

Your email address will not be published. Required fields are marked *