Search code examples
javascriptjquerycakephpbuttonformhelper

HTML style input with Cakephp Action


In my index.ctp, I am creating a table and the last column of the table will have 3 buttons to perform actions on that specific row. The buttons will be View, Edit, and Delete.

I am trying to decide what will be easier, using cakephp's form helper to create a button and link the button with the corressponding controller action, or use javascript to create the input but then how would I link the onclick to the controller action.

I am a total noob at cakephp so any help would be great.

Here is the code for the buttons using the form:

<td><input type="button" id="viewButton" value="View"/><input type="button" id="editButton" value="Edit"/><input type="button" id="deleteButton" value="Delete"/></td>

(I don't have any events on the button becase I don't know how to link the events to the controller)

Here is the same thing but written with cakephp's form helper:

<td><?php echo $this->Form->button('View', array('type' => 'button', 'action' => 'view'), $LocalClock['LocalClock']['id']);
echo $this->Form->button('Edit', array('type' => 'button', 'action' => 'edit', $LocalClock['LocalClock']['id']));
echo $this->Form->button('Delete', array('type' => 'button', 'action' => 'delete', $LocalClock['LocalClock']['id']));?>
</td>

I needed help with getting the buttons to communicate with their actions. Ultimately I will try and open a modal window with one of the views in the window.

Thanks in advance


Solution

  • I found an answer to my own question.

    I can use a button like this

    <button onclick="location.href='<?php echo $html->url('/controller/ 
    action'); ?>';">Click me</button> 
    

    When adjusted to fit my specific program I got

    <td> <input type="button" class="viewButton" value="View" onclick="location.href='<?php echo $this->Html->url(array('controller' => 'localClocks', 'action' => 'view', $LocalClock['LocalClock']['id'])); ?>';"/>
        <input type="button" class="editButton" value="Edit" onclick="location.href='<?php echo $this->Html->url(array('controller' => 'localClocks', 'action' => 'edit', $LocalClock['LocalClock']['id'])); ?>';"/>
    

    Html->url(array('controller' => 'localClocks', 'action' => 'delete', $LocalClock['LocalClock']['id'])); ?>';"/>

    I just thought I would share what I found. Thanks