Ich habe ein Formular mit dynamischen Feldern. Wenn ich ein dynamisches Feld hinzufüge und eine var_dump
dieses Feldes mache, bekomme ich nur das erste Ergebnis.PHP - dynamische Felder Array nicht
Form:
<div class="form-group halltype">
<label class="col-sm-2 col-sm-2 control-label">HallType</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="title1[]" placeholder="Main Title"><br />
<input type="text" class="form-control" name="title2[]" placeholder="Title 2"><br />
<input type="text" class="form-control" name="seating[]" placeholder="Seating Capacity"><br />
<input type="text" class="form-control" name="floating[]" placeholder="Floating Capacity"><br />
</div>
</div>
<div class="form-group addhalltype">
<label class="col-sm-2 col-sm-2 control-label"></label>
<div class="col-sm-10">
<input type="button" class="btn btn-info" id="">Add Hall Type</button>
</div>
JQuery:
$(".addhalltype").click(function() {
$halltype = '<div class="form-group halltype"><label class="col-sm-2 col-sm-2 control-label">HallType</label><div class="col-sm-10"><input type="text" class="form-control" name="title1[]" placeholder="Main Title"><br /><input type="text" class="form-control" name="title2[]" placeholder="Title 2"><br /><input type="text" class="form-control" name="seating[]" placeholder="Seating Capacity"><br /><input type="text" class="form-control" name="floating[]" placeholder="Floating Capacity"><br /></div></div>';
$($halltype).insertBefore(".addhalltype");
});
und wenn ich var_dump($_POST['title1'])
tun, erhalte ich
array(1) {
[0]=>
string(4) "1212"
}
wenn dynamische Felder in einem Formular verwendet, wenn mehrere Elemente sind Sie in einem Array zurückgeben möchten [ 'title'] Sie erhalten ein Array mit allen Items – happymacarts
Ich sehe auch kein '' Element und mache auch eine Annahme, dass Sie dieses "Formular" auf eine PHP Seite posten, dass Sie var_dumping/die Antwort behandeln mit – happymacarts