This is my first post. I have searched for other solutions and what I've found only deals with components of this question. Basically this is what I'd like to do:
- Capture form data (tested, working);
- Convert form data using serializeArray() or serialize() (tested both options, working and outputs to console correctly);
- Send this information to the server through Ajax (not working); and
- PHP saves array as a CSV (not yet started).
Bellow is the code I'm using. But first, here are some alternatives I've tried. Usually I get this: array(0) { }
- 'dataType' as Json - returns error;
- 'GET', 'POST' and 'REQUEST' - PHP shows empty array;
- use form.serialize() - PHP shows empty array;
- use form.serializeArray() - PHP shows empty array; and
var_dump($_POST), var_dump($_GET), var_dump($_REQUEST).
var serialisedForm = $(form).serializeArray(); var serialisedData = JSON.stringify(serialisedForm); console.log(serialisedData); //working console.log(serialisedForm); //working $.ajax({ type: "POST", url: "datacapture.php", data: { serialisedForm, //tested using serialisedData as well }, success: function() { window.open('datacapture.php'); }, error: function() { alert("the form data has not been sent to the server"); } })
and here is the datacapture.php script I'm using to test the information flow.
<?php
var_dump($_POST);
?>
EDIT - and here is a sample form item, reading .text and .name from my settings.json file:
<tbody>
{
this.props.settings.schemes[0].questions.map((q, i)=> {
return <tr><td>{q.text}</td><td><div class="YesNo"><input type="radio" required name={q.name} value="yes">Yes</input><input type="radio" required name={q.name} value="no">No</input></div></td></tr>
})
}
</tbody>