торт php превратить ссылку в кнопку - PullRequest
0 голосов
/ 04 августа 2020

Я хочу заменить ссылку удаления сообщения на кнопку. Я пробовал много комбинаций, но изменение на кнопку приводит к отправке формы, а не к перенаправлению к методу удаления.

Не уверен, что осталось попробовать.

<?= $this->Form->postButton(__('X', ['type' => 'button']), ['controller' => 'StrategiesConditions', 'action' => 'delete', $strategiesConditions['id']], ['confirm' => __('Are you sure you want to delete # {0}?', $strategiesConditions['id'])]) ?>

Общий код

    <div class="strategies form content">
        <?= $this->Form->create($strategy) ?>
        <fieldset>
            <legend><?= __('Edit Strategy') ?></legend>
            <?php
                echo $this->Form->control('user_id', ['options' => $users]);
                echo $this->Form->control('name');
                echo $this->Form->control('description');
                echo $this->Form->control('one_hundred_trades');
            ?>
            <table id="conditions-table">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Level</th>
                        <th></th>
                    </tr>
                    <tr>
                        <td>
                            <input id="condtitions-input"></input>
                            <select id="condtitions-level">
                                <option value="Mandatory">Mandatory</option>
                                <option value="Important">Important</option>
                                <option value="Support">Support</option>
                            </select>
                        </td>
                        <td>
                            <button id="add-condtition" type='button' onclick="addCondition()">Add Conditions</button></td>
                        </td>  
                    </tr>
                    <?php foreach ($strategy->strategies_conditions as $key=>$strategiesConditions) : ?>
                    <tr>
                        <td>
                            <?php echo $this->Form->hidden('strategies_conditions.' . $key . '.id'); ?>
                            <?php echo $this->Form->control('strategies_conditions.'.$key.'.name', array( 'label' => false )); ?>
                            <select name="strategies_conditions[<?=$key?>][level]">
                                <option <?= ($strategiesConditions['level'] == "Mandatory") ? 'selected="selected"' : "" ?> value="Mandatory">Mandatory</option>
                                <option <?= ($strategiesConditions['level'] == "Important") ? 'selected="selected"' : ""  ?> value="Important">Important</option>
                                <option <?= ($strategiesConditions['level'] == "Support") ? 'selected="selected"' : ""  ?> value="Support">Support</option>
                            </select>
                        </td>
                        <td>
                            <?= $this->Form->postLink(__('X', ['type' => 'button']), ['controller' => 'StrategiesConditions', 'action' => 'delete', $strategiesConditions['id']], ['confirm' => __('Are you sure you want to delete # {0}?', $strategiesConditions['id'])]) ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>                       
                </thead>
            </table>                
        </fieldset>
        <?= $this->Form->button(__('Submit')) ?>
        <?= $this->Form->end() ?>
    </div>

1 Ответ

0 голосов
/ 04 августа 2020

Я использовал Cake php block для решения проблемы form с form и добавил стиль, чтобы сделать его похожим на кнопку.

<?= $this->Form->postLink(__('X'), 
       [
          'controller' => 'StrategiesConditions', 
          'action' => 'delete', 
           $strategiesConditions->id
       ], 
       [
           'block' => true,
           'class' => 'btn btn-primary',
           'confirm' => __('Are you sure you want to delete # {0}?', $strategiesConditions['id'])
           ]) ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>                       
                </thead>
            </table>                
        </fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
<?=  $this->fetch('postLink'); ?>
...