1
背景情報jqueryの - 動的フォームにフィールドを追加する - あなたは、フォームに送信したときのポストは、データが欠落している
私はとりわけ、ユーザーが動的に最初の名前/姓のテキストフィールドを追加することを可能にするという形を持っていますjqueryを使用します。
問題
ユーザーがデータを送信すると、jqueryのを使用して作成された追加のフィールド&データはPOSTから欠落しています。
テストの詳細
「addname」ボタンを使用して、私は、フォーム上にあるデフォルトFNAME/LNAMEフィールド以外にも二、三追加の名前を追加します。そして、データを提出します。データに動的に追加されたフィールドがありません。
をチェック私が試した何
は/私は「最初の名前」/「姓」テキストボックスの新しい行を追加すると、各コントロールは、独自の「名前」を持っていることを確実にしました。あなたが見ることができるように、私は最初の名前のフィールドにカスタムクラス名を割り当て、jqueryで私はすでにいくつのファーストネームフィールドを数えます。その値を1ずつ増やして、作成した新しいテキストフィールドの名前に新しい番号を書き出します。 F12デバッグウィンドウを使用すると、HTMLコードにはこれらのカウンタが名前に焼き付けられていることがわかります。
は、動的に追加されたデータの行が
<FORM>
以内に私はFORM内のボタンを提出していることを保証されていることを確実にしました。
私は他に何を確認すべきかわかりません。
ご意見がありましたら、感謝します。
//Here's of the two jquery methods I have that allows users to dynamically add new fields/data to the form:
$("#addname").click(function() {
var numItems = $('.widgetname').length; //count all items with widgetname class
numItems += 1;
htmlstring = "<tr>";
htmlstring += "<td><input class='form-control widgetname' type='input' placeholder='First Name' name='fname" + numItems + "'/></td>";
htmlstring += "<td colspan='2'><input class='form-control' type='input' placeholder='Last Name' name='lname" + numItems + "' /></td>";
htmlstring += "</tr>";
$("#tcsection").before(htmlstring);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<table class="table table-bordered table-hover">
<tr>
<td colspan="3" class="btn-warning">
<?php echo validation_errors(); ?>
</td>
<tr>
<?php echo form_open('widget/assign'); ?>
<tr>
<td colspan="3">
<div class="form-group">
<select class="form-control" name="widgetlist" id="widgetnum">
</select>
</div>
</td>
</tr>
<tr>
<td colspan="3">
<div class="form-group">
<select class="form-control" placeholder="Site:" name="site" id="site">
</div>
</td>
</tr>
<tr>
<td colspan="3">
<input class="form-control" type="input" placeholder="Location" name="location" />
</td>
</tr>
<tr>
<td colspan="3">
<input class="form-control" type="input" placeholder="Department" name="department" />
</td>
</tr>
<tr id="listofnames">
<td>
<input class="form-control widgetname" type="input" placeholder="First Name" name="fname" />
</td>
<td>
<input class="form-control" type="input" placeholder="Last Name" name="lname" />
</td>
<td>
<button id='addname' type="button" class="btn btn-info btn-circle"><i class="fa fa-plus"></i>
</button>
</td>
</tr>
<tr id="tcsection">
<td colspan="3"> </td>
</tr>
</table>
<table class="table table-bordered table-hover">
<tr>
<td colspan="5">
<h2>TC</h2>
</td>
</tr>
<tr id="tcs">
<td>
<input class="form-control starttc" type="input" placeholder="UTC Start Time (format 00:00:00)" name="starttime" />
</td>
<td>
<input class="form-control" type="input" placeholder="UTC End Time (format 00:00:00)" name="endtime" />
</td>
<td>
<input class="form-control" type="input" placeholder="Extension" name="extension" />
</td>
<td>
<input class="form-control" type="input" placeholder="Domain" name="domain" />
</td>
<td>
<button id='addtc' type="button" class="btn btn-success btn-circle"><i class="fa fa-plus"></i>
</button>
</td>
</tr>
<tr id="submitbtnsection">
<td colspan="5">
<input type="submit" name="submit" class="btn btn-primary" value="Assign Widget" />
</td>
</tr>
</form>
</table>
True @mplungjan - 私がコメントしてしまう前に、私はそれほど遠く離れていませんでした。 –
実際にテストできるHTMLコードを投稿できますか?あなたにはPHPが入っています。 –
フォームを表の外に開いて移動してみてください。私は奇妙なhtmlを参照してください: '
答えて
表外のオープンフォームを移動してみてください。
私は今、奇妙なHTMLをご覧ください:
intead私は
PS予想:あなたが使用してフォームを送信することを計画している場合は=任意のフォーム要素のための「送信」の名前を使うべきではありませんがスクリプト。投稿イベントハンドラを上書きします
出典
2016-11-08 16:00:07 mplungjan
関連する問題