I'm having issues using .serialize() on the following form:
<form id="cfgedit">
<div class="card hoverable">
<div class="card-content">
<div class="row center-align">
<div class="col s12 m4 input-field"><input type="text" id="bpid" name="bpid" value="" /><label for="bpid">Business Partner</label></div>
<div class="col s12 m4 input-field"><input type="text" id="serviceid" name="serviceid" value="" /><label for="serviceid">Service ID</label></div>
<div class="col s12 m4 input-field"><input type="text" id="servicetype" name="servicetype" value="" /><label for="servicetype">Service Type</label></div>
</div>
<div class="row teal lighten-5">
<div class="input-field col s12">
<textarea id="smstext" name="smstext" class="materialize-textarea flow-text" length="160"></textarea>
<label for="smstext">SMS Text</label>
</div>
</div>
<div class="row">
<div class="col s12 m6 input-field right-align"><input type="text" id="url" name="url" value="" /><label for="url">Url destinazione</label></div>
<div class="col s12 m6"><strong>Validità:</strong><br />
<input type="number" name="validityD" min="0" value="1"> d
<input type="number" name="validityH" min="0" max="23" value="0"> h
<input type="number" name="validityM" min="0" max="59" value="0"> m
</div>
</div>
</div>
<div class="card-action">
<a class="btn btn-large waves-effect red" href="/admin">Cancel</a>
<a class="waves-effect btn-large right" id="persist">Save</a>
</div>
</div>
</form>
I'm using $.ajax to post the form to my back-end, bound to #persist button click.
$.ajax({
type: "POST",
url: "/admin/config/add",
data: $("#cfgedit").serialize(),
success: function(data) {
// display ok
},
error: function(data)
{
// display not ok
}
});
Now the issue I'm facing is with the $.ajax data. Because using Chrome's console and typing $("#cfgedit").serialize(); I do get the correct form serialization:
"bpid=TEST_BP&serviceid=TEST_SID&servicetype=TEST_ST&smstext=SMS_TEXT&url=http%3A%2F%2Ftest.url&validityD=1&validityH=2&validityM=3"
But if I send the form, that same serialize returns only
"smstext=SMS_TEXT"
The fields I'm expecting in output all have name attribute set.