How to use FormHelper :: postLink () inside a form?

I want to create a Cakephp delete delete link in a form similar to the following. But the very first button to delete a message does not include the delete Form when I check in the browser and cannot delete, but the rest include as I want and can delete.

Is this a cakephp error or something that I need to change the source code?

<?php
echo $this->Form->create('Attendance', array('required' => false, 'novalidate' => true));

foreach($i = 0; $i < 10; i++):
    echo $this->Form->input('someinput1', value => 'fromdb');
    echo $this->Form->input('someinput2', value => 'fromdb');
    echo $this->Form->postLink('Delete',array('action'=>'delete',$attendanceid),array('class' => 'btn btn-dark btn-sm col-md-4','confirm' => __('Are you sure you want to delete')));
endforeach;

echo $this->Form->button('Submit', array('class' => 'btn btn-success pull-right'));
echo $this->Form->end();
?>
+4
source share
1 answer

Forms cannot be nested ; the HTML standard prohibits this by definition. If you try, most browsers will reset the sub form and display its content outside the parent form.

, inline block ( CakePHP 2.5, inline CakePHP 3.x), , .

CakePHP 2.x

echo $this->Form->postLink(
    'Delete',
    array(
        'action' => 'delete',
        $attendanceid
    ),
    array(
        'inline' => false, // there you go, disable inline rendering
        'class' => 'btn btn-dark btn-sm col-md-4',
        'confirm' => __('Are you sure you want to delete')
    )
);

CakePHP 3.x

echo $this->Form->postLink(
    'Delete',
    [
        'action' => 'delete',
        $attendanceid
    ],
    [
        'block' => true, // disable inline form creation
        'class' => 'btn btn-dark btn-sm col-md-4',
        'confirm' => __('Are you sure you want to delete')
    ]
);

// ...

echo $this->Form->end();

// ...

echo $this->fetch('postLink'); // output the post link form(s) outside of the main form

.

CakePHP 2.x

CakePHP 3.x

+13

Source: https://habr.com/ru/post/1625939/


All Articles