使用 post 方法从克隆字段中获取值
taking values using post method from a cloned field
<table class="manual_journal_table table table-bordered">
<tr>
<th>Account</th>
<th>Party</th>
<th>Debit</th>
<th>Credit</th>
<th>Action</th>
</tr>
<tr id="clone">
<td><input type="text" required name="account" id="account"></td>
<td><input type="text" required name="party" id="party"></td>
<td><input type="text" required name="debit" id="debit"></td>
<td><input type="text" required name="credit" id="credit"></td>
<td><a href="#" class="removejournal btn btn-flat btn-danger">Remove</a></td>
</tr>
</table>
<a href="#" class="add_new_row btn btn-flat btn-success">Add New Row</a>
我想使用 post 方法从克隆的 table 中获取值,然后我想将其插入数据库 table
因为有可能添加更多行,这实际上意味着更多值。由于您只添加没有数组值的名称,因此这些值将被覆盖,您不会获得所有值。
例如:将 name="account"
改为 name="account[]"
如果我是你,那么我会采取更好的方法,使用格式正确的数组,以便将数据适当地发布到操作中,如下所示
Observer name 字段仔细,甚至我已经将 id 替换为 class
Note : I higly suggest you not to create table for every new row added
instead append that to the current table as follows
<tr class="clone">
<td><input type="text" required name="payment_details[1][account]" class="account"></td>
<td><input type="text" required name="payment_details[1][party]" class="party"></td>
<td><input type="text" required name="payment_details[1][debit]" class="debit"></td>
<td><input type="text" required name="payment_details[1][credit]" class="credit"></td>
<td><a href="#" class="removejournal btn btn-flat btn-danger">Remove</a></td>
</tr>
<tr class="clone">
<td><input type="text" required name="payment_details[2][account]" class="account"></td>
<td><input type="text" required name="payment_details[2][party]" class="party"></td>
<td><input type="text" required name="payment_details[2][debit]" class="debit"></td>
<td><input type="text" required name="payment_details[2][credit]" class="credit"></td>
<td><a href="#" class="removejournal btn btn-flat btn-danger">Remove</a></td>
</tr>
现在在您的控制器操作或相应页面中,您将获得以下格式的数据
payment_details =>
[1] =>
[account] => 'xyz'
[party] => 'xyz'
[debit] => 'xyz'
[credit] => 'xyz'
[2] =>
[account] => 'xyz'
[party] => 'xyz'
[debit] => 'xyz'
[credit] => 'xyz'
您可以通过循环进入 payment_details
轻松管理
<table class="manual_journal_table table table-bordered">
<tr>
<th>Account</th>
<th>Party</th>
<th>Debit</th>
<th>Credit</th>
<th>Action</th>
</tr>
<tr id="clone">
<td><input type="text" required name="account" id="account"></td>
<td><input type="text" required name="party" id="party"></td>
<td><input type="text" required name="debit" id="debit"></td>
<td><input type="text" required name="credit" id="credit"></td>
<td><a href="#" class="removejournal btn btn-flat btn-danger">Remove</a></td>
</tr>
</table>
<a href="#" class="add_new_row btn btn-flat btn-success">Add New Row</a>
我想使用 post 方法从克隆的 table 中获取值,然后我想将其插入数据库 table
因为有可能添加更多行,这实际上意味着更多值。由于您只添加没有数组值的名称,因此这些值将被覆盖,您不会获得所有值。
例如:将 name="account"
改为 name="account[]"
如果我是你,那么我会采取更好的方法,使用格式正确的数组,以便将数据适当地发布到操作中,如下所示
Observer name 字段仔细,甚至我已经将 id 替换为 class
Note : I higly suggest you not to create table for every new row added instead append that to the current table as follows
<tr class="clone">
<td><input type="text" required name="payment_details[1][account]" class="account"></td>
<td><input type="text" required name="payment_details[1][party]" class="party"></td>
<td><input type="text" required name="payment_details[1][debit]" class="debit"></td>
<td><input type="text" required name="payment_details[1][credit]" class="credit"></td>
<td><a href="#" class="removejournal btn btn-flat btn-danger">Remove</a></td>
</tr>
<tr class="clone">
<td><input type="text" required name="payment_details[2][account]" class="account"></td>
<td><input type="text" required name="payment_details[2][party]" class="party"></td>
<td><input type="text" required name="payment_details[2][debit]" class="debit"></td>
<td><input type="text" required name="payment_details[2][credit]" class="credit"></td>
<td><a href="#" class="removejournal btn btn-flat btn-danger">Remove</a></td>
</tr>
现在在您的控制器操作或相应页面中,您将获得以下格式的数据
payment_details =>
[1] =>
[account] => 'xyz'
[party] => 'xyz'
[debit] => 'xyz'
[credit] => 'xyz'
[2] =>
[account] => 'xyz'
[party] => 'xyz'
[debit] => 'xyz'
[credit] => 'xyz'
您可以通过循环进入 payment_details
轻松管理