-3

I have dynamically created forms (there are quite a few different forms with a variable number of input fields) and want to “submit” them via a generic AJAX call to update tables in a MYSQL database (this I can do).

My problem is how to obtain a form's $_POST variables with jquery or javascript so I can json_encode them.

I found a lot of answers but all used the field name's #id to access the data. I have spent over 3 hours googling with no success because I believe I may have been unable to phrase the question correctly.

The closest reply I found was How to retrieve $_POST variable from jquery serializearray() but was unable to relate this to my problem.

Community
  • 1
  • 1
  • Why the -3. If you are going to mark me down have the good manners to let me know why so I won't make the same mistake again. – Casandra Tera Dec 17 '14 at 22:52
  • I don't understand what you're trying to do. Do you want to collect the data from the form fields? If so, why doesn't that other answer work for you? Help us help you. – Evan Davis Dec 17 '14 at 23:00
  • Thank you for helping me. I do not want to leave the web page, I want to update a DB table. The submit button points to a javascript function which does an AJAX call. I need the $_POST data to send to the PHP file it calls update the table. – Casandra Tera Dec 17 '14 at 23:16
  • You are confusing server-side PHP `$_POST` with... well, I don't know what you're trying to get instead, and that's the problem. – Evan Davis Dec 17 '14 at 23:46
  • On submit the form generates an array of $_POST variables I need to access them in a javascript function. – Casandra Tera Dec 18 '14 at 00:28

1 Answers1

0

I finally found the answer to what I wanted.

Obtain form input fields using jQuery?

$('#myForm').submit(function() {
    // get all the inputs into an array.
    var $inputs = $('#myForm :input');

    // not sure if you wanted this, but I thought I'd add it.
    // get an associative array of just the values.
    var values = {};
    $inputs.each(function() {
        values[this.name] = $(this).val();
    });

});

I would like to thank the kind people who took the time to help me.

Community
  • 1
  • 1