2013-02-24 2 views
0

Я хочу иметь несколько форм под каждой строкой таблицы на странице с cakephp. Я не уверен, как изменить имена ввода, чтобы это разрешить.cakephp несколько форм

<table cellpadding="0" cellspacing="0"> 
    <tr> 
      <th><?php echo $this->Paginator->sort('id'); ?></th> 
      <th><?php echo $this->Paginator->sort('member_no'); ?></th> 
      <th><?php echo $this->Paginator->sort('first_name'); ?></th> 
      <th><?php echo $this->Paginator->sort('last_name'); ?></th> 
      <th><?php echo $this->Paginator->sort('total_points'); ?></th> 
      <th><?php echo $this->Paginator->sort('date_joined'); ?></th> 
      <th class="actions"><?php echo __('Actions'); ?></th> 
    </tr> 
    <?php foreach ($members as $member): ?> 
    <tr> 
     <td><?php echo h($member['Member']['id']); ?>&nbsp;</td> 
     <td><?php echo h($member['Member']['member_no']); ?>&nbsp;</td> 
     <td><?php echo h($member['Member']['first_name']); ?>&nbsp;</td> 
     <td><?php echo h($member['Member']['last_name']); ?>&nbsp;</td> 
     <td><?php echo h($member['Member']['total_points']); ?>&nbsp;</td> 
     <td><?php echo h($member['Member']['date_joined']); ?>&nbsp;</td> 
     <td class="actions"> 
      <?php echo $this->Html->link(__('View'), array('action' => 'view', $member['Member']['id'])); ?> 
      <?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $member['Member']['id'])); ?> 
      <?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $member['Member']['id']), null, __('Are you sure you want to delete # %s?', $member['Member']['id'])); ?> 
     </td> 
    </tr> 
    <tr> 
     /// This is the form for each record 
     <td> 
      <?php echo $this->Form->create('Point', array('action' => 'add')); ?> 
       <fieldset> 
        <legend><?php echo __('Add Point'); ?></legend> 
       <?php 
        echo $this->Form->input('member_id',array('type'=>'hidden', 'value'=>$member['Member']['id'])); 
        echo $this->Form->input('points'); 
       ?> 
       </fieldset> 
      <?php echo $this->Form->end(__('Submit')); ?> 
     </td> 
    </tr> 
<?php endforeach; ?> 
    </table> 

ответ

0

CakePHP будет производить формы как обычно, если они уникально названы. Вы могли бы рассмотреть добавление идентификатора участника на имя формы:

<?php echo $this->Form->create('Point'.$member['Member']['id'], array('action' => 'add')); ?> 

Вы можете использовать это (или любой другой метод, который вы хотели бы), чтобы сделать формы уникальными. У вас может также возникнуть проблема с именами неповторимых полей. В этом случае используйте аналогичный трюк, чтобы иметь все уникальные имена полей в обеих формах и полях, если они принадлежат одному контроллеру.

+0

Я думал об этом, но у меня отсутствует контроллер Point1s –

+0

Вам нужно будет вручную указать контроллер, если он называет форму разными вещами. ' Form-> create ('Point'. $ member ['Member'] ['id'], array ('controller' => 'myController', 'action' => 'add')); ?> ' – swiecki

Смежные вопросы