I try to submit a form via AJAX and then work with the values. Here is the markup of the form:
<form id="formDeb" action="controller/processDeb.php" method="POST" enctype="multipart/form-data">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="formGroupName">Angezeigter Name in Cydia/Sileo</label>
<input type="text" class="form-control" id="formGroupName" name="formGroupName"
placeholder="Vorname Nachname oder Kürzel">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="formGroupMail">Deine E-Mail Adresse</label>
<input type="email" class="form-control" id="formGroupMail" name="formGroupMail"
placeholder="Deine E-Mail Adresse">
</div>
</div>
<!-- and more fields -->
</form>
I submit the form via Ajax:
var myFormData = new FormData(this);
var supportedDevices = getSelectedBoxes("devices");
var supportedVersions = getSelectedBoxes("iosversions");
myFormData.append("supportedDevices", supportedDevices);
myFormData.append("supportedVersions", supportedVersions);
$.ajax({
type: method,
url: targetUrl,
data: myFormData,
processData: false,
async: true,
beforeSend: function () {
isSubmitting = true;
$btnSubmit.attr('disabled', 'true');
$btnImg.toggle();
$btnLoader.toggle();
}
})
in the processDeb.php File i have this code:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (is_array($_POST)) {
echo '<pre>' . var_export($_POST, true) . '</pre>';
$name = $_POST['cName'] ?? '';
$mail = $_POST['cMailAddress'] ?? '';
}
The values are should be set, but when I try to access $name or $mail the content is ''.
The output of the var_export is the following:
array ( '------WebKitFormBoundaryMBXZo8GpgumN5Etl Content-Disposition:_form-data;_name' => '"formGroupName"
fancy name ------WebKitFormBoundaryMBXZo8GpgumN5Etl Content-Disposition: form-data; name="formGroupMail"
So it should be possible to access the values using $_POST['formGroupName'] but it is not possible.
The enctype is set to multipart/form-data because there are also some upload fields for the user.