Создать форму в строке html таблицы в режиме cakephp

Я пытаюсь создать форму внутри таблицы td в цикле foreach программы cakePHP, я хочу создать только 3 таблицы td и обновить ее. Кроме того, она работает нормально, но проблема заключается только в выравнивании заголовка из-за формы внутри td. Если я достану форму из пф тд, это не сработает

<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']))); ?>&nbsp;</td>
        <td><?php echo h(date('d-M-y',strtotime($order['Order']['delivery_date']))); ?>&nbsp;</td>
        <td><?php echo h($status[$order['Order']['status']]); ?>&nbsp;</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>

Но это нарушает выравнивание таблицы th и td:

введите описание изображения здесь

Пожалуйста, помогите мне. Заранее благодарю.

2 ответа

Решение

Попробуй это

<?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']))); ?>&nbsp;</td>
  <td><?php echo h(date('d-M-y',strtotime($order['Order']['delivery_date']))); ?>&nbsp;</td>
        <td><?php echo h($status[$order['Order']['status']]); ?>&nbsp; 
  </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(); ?>

Ваш th а также td не равны th 8 и td только 6 (именно поэтому ваша колонка смешивается)

<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']))); ?>&nbsp;</td>
        <td><?php echo h(date('d-M-y',strtotime($order['Order']['delivery_date']))); ?>&nbsp;</td>
        <td><?php echo h($status[$order['Order']['status']]); ?>&nbsp;</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>
Другие вопросы по тегам