I would like to convert a link into a button using CakePHP Helpers.
With $this->Html->link()
I am able to use an array() to include 'action' => 'view' . $user['User']['id']
, but I am not sure how to include this when using $this->Form->button()
instead.
Using $this->Html->link()
:
$this->Html->link('Click me', array(
'controller' => 'users',
'action' => 'view' . $user['User']['id']));
My solutions do not allow me to add 'action' => 'view' . $user['User']['id']
Using $this->Form->button()
:
echo $this->Form->button('Click me', array(
'type' => 'button',
'onclick' => 'location.href=\'/rentmyride/users/index/\';',
));
Using <input>
tag:
<input type="button" class="btn btn-primary" value="Click me"
onclick="location.href='http://www.domain.com';">
Using <button>
tag:
<button class="btn btn-success" onclick="location.href='http://www.domain.com';">
Click me
</button>
Using button tag inside <a> tag: This method create a button inside anchor tag. The anchor tag redirect the web page into the given location. Adding styles as button to a link: This method create a simple anchor tag link and then apply some CSS property to makes it like a button.
HTML buttons cannot have href attribute if they are created using button <button> </button> HTML tags. However, you can use href attribute if you create the buttons using link <a> </a> HTML tags.
HTML5 buttons have a formaction attribute for this use. Of course this works only in modern browsers
$this->Form->button(
'Click me',
array(
'formaction' => Router::url(
array('controller' => 'users','action' => 'view' . $user['User']['id'])
)
)
);
if you are using cakephp 2.X and above please use this line of code for link in button:
<button onclick="window.location.href='<?php echo Router::url(array('controller'=>'Users', 'action'=>'admin_index'))?>'">;Go Back</button>;
I hope this is works for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With