Reputation: 171
I am trying to create form inside table td in foreach loop of cakePHP, I want to form in only 3 table td and update it in. Also, it is working fine but only issue is with alignment of heading because of form inside td. If I take out form out pf td, it doesn't work
<table class="table table-hover ">
<thead>
<tr>
<th>Customer</th>
<th>Dress</th>
<th>Order Date</th>
<th>Delivery Date</th>
<th>Status</th>
<th>Tailor</th>
<th>Tailor Cost</th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<tr>
<td>
<?php echo $this->Html->link($order['Customer']['name'], array('controller' => 'customers', 'action' => 'view', $order['Customer']['id'])); ?>
</td>
<td>
<?php echo $this->Html->link($order['Dress']['type'], array('controller' => 'dresses', 'action' => 'view', $order['Dress']['id'])); ?>
</td>
<td><?php echo h(date('d-M-y',strtotime($order['Order']['order_date']))); ?> </td>
<td><?php echo h(date('d-M-y',strtotime($order['Order']['delivery_date']))); ?> </td>
<td><?php echo h($status[$order['Order']['status']]); ?> </td>
**<td>
<?php echo $this->Form->create('Order',['class'=>'form-inline']); ?>
<?php echo $this->Form->input('id', ['type'=>'hidden','value'=>$order['Order']['id']]); ?>
<?php echo $this->Form->input('user_id', ['empty'=>'--Select--','options'=>$users, 'selected'=>$order['User']['id'], 'div' => false, 'label' => false, 'class' => 'form-control']); ?>
<?php echo $this->Form->input('tailor_price', ['value' =>$order['Order']['tailor_price'], 'div' => false, 'label' => false, 'class' => 'form-control','style'=>'max-width:140px;']); ?>
<?php echo $this->Form->button(__('Update'), ['class' => 'btn btn-default']) ?>
<?php echo $this->Form->end(); ?>
</td>**
</tr>
<?php endforeach; ?>
</tbody>
But it's breaking the table th and td alignment :
Please help me out. Thank you in advanced.
Upvotes: 2
Views: 1054
Reputation: 80
your th
and td
are not equal th
are 8 and td
are only 6
(which is why your column are mixing)
<table class="table table-hover ">
<thead>
<tr>
<th>Customer</th>
<th>Dress</th>
<th>Order Date</th>
<th>Delivery Date</th>
<th>Status</th>
<th>Tailor</th>
<th>Tailor Cost</th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<tr>
<?php echo $this->Form->create('Order',['class'=>'form-inline']); ?>
<td>
<?php echo $this->Html->link($order['Customer']['name'], array('controller' => 'customers', 'action' => 'view', $order['Customer']['id'])); ?>
</td>
<td>
<?php echo $this->Html->link($order['Dress']['type'], array('controller' => 'dresses', 'action' => 'view', $order['Dress']['id'])); ?>
</td>
<td><?php echo h(date('d-M-y',strtotime($order['Order']['order_date']))); ?> </td>
<td><?php echo h(date('d-M-y',strtotime($order['Order']['delivery_date']))); ?> </td>
<td><?php echo h($status[$order['Order']['status']]); ?> </td>
<td>
<?php echo $this->Form->input('id', ['type'=>'hidden','value'=>$order['Order']['id']]); ?>
<?php echo $this->Form->input('user_id', ['empty'=>'--Select--','options'=>$users, 'selected'=>$order['User']['id'], 'div' => false, 'label' => false, 'class' => 'form-control']); ?>
</td>
<td>
<?php echo $this->Form->input('tailor_price', ['value' =>$order['Order']['tailor_price'], 'div' => false, 'label' => false, 'class' => 'form-control','style'=>'max-width:140px;']); ?>
</td>
<td>
<?php echo $this->Form->button(__('Update'), ['class' => 'btn btn-default']) ?>
</td>
<?php echo $this->Form->end(); ?>
</tr>
<?php endforeach; ?>
</tbody>
Upvotes: 0
Reputation: 151
try this
<?php echo $this->Form->create('Order',['class'=>'form-inline']); ?>
<td>
<?php echo $this->Html->link($order['Customer']['name'], array('controller' => 'customers', 'action' => 'view', $order['Customer']['id'])); ?>
</td>
<td>
<?php echo $this->Html->link($order['Dress']['type'], array('controller' => 'dresses', 'action' => 'view', $order['Dress']['id'])); ?>
</td>
<td><?php echo h(date('d-M-y',strtotime($order['Order']['order_date']))); ?> </td>
<td><?php echo h(date('d-M-y',strtotime($order['Order']['delivery_date']))); ?> </td>
<td><?php echo h($status[$order['Order']['status']]); ?>
</td>
<td>
<?php echo $this->Form->input('id', ['type'=>'hidden','value'=>$order['Order']['id']]); ?>
<?php echo $this->Form->input('user_id', ['empty'=>'--Select--','options'=>$users, 'selected'=>$order['User']['id'], 'div' => false, 'label' => false, 'class' => 'form-control']); ?>
</td>
<td>
<?php echo $this->Form->input('tailor_price', ['value' =>$order['Order']['tailor_price'], 'div' => false, 'label' => false, 'class' => 'form-control','style'=>'max-width:140px;']); ?>
</td>
<td>
<?php echo $this->Form->button(__('Update'), ['class' => 'btn btn-default']) ?>
</td>
<?php echo $this->Form->end(); ?>
Upvotes: 0