Hello:
I have a register action in my site to allow the guest user to create a new account for him.
Also I have a button in my index page with a link to the register action and that’s where my problem begins. I tried with this:
<?php echo CHtml::button('Register', array('submit' => array('site/register'))); ?>
When I click the button nothing happens. I also tried with a link:
<?php echo CHtml::link('LinkText',array('site/register'),array('class'=>'btn_registro')); ?>
And it works perfectly but… I want a button !! hehe
I’d appreciate any help please. :S
zaccaria
(Matteo Falsitta)
May 12, 2011, 6:41am
2
Just use a link and style it as a button. Buttons worls properly only in forms, you should create a form with action the action you want, and put the button in the form.
A better approach is to use links, using the background you can style the link as a button, and even better.
_Stan
(_Stan_)
January 23, 2013, 7:51pm
3
For those who may be interested in implementing the same behaviour, I’m just faced the same problem and solved it with the following code:
CHtml::button('Title', array('onclick' => 'js:document.location.href="controller/action"'));
Works for me.
Inside the referrence in a button you add
index.php?r=
before a controller/action. Like this:
js:document.location.href="index.php?r=controller/action"
shgninc
(Shgninc)
August 7, 2013, 6:51am
6
Also you can use CHtml::linkButton()
andrea.p
(Andrea)
September 21, 2013, 8:27am
7
For those who may be interested in implementing the same behaviour, I’m just faced the same problem and solved it with the following code:
CHtml::button('Title', array('onclick' => 'js:document.location.href="controller/action"'));
Works for me.
Thanks!It works, but ignore all $_GET data, you have insert it like this:
<?php echo CHtml::button('Title', array('onclick' => 'js:document.location.href="index.php?r=controller/action&id='.$model->id.'"')); ?>
istead of:
<?php echo CHtml::link('Title', array('controller/action', 'id'=>$model->id)); ?>
f.gruber
(Ferdinand)
September 11, 2014, 10:40am
8
zaccaria:
Just use a link and style it as a button. …
A better approach is to use links, using the background you can style the link as a button, and even better.
Please can you help me:
How to style a link as a button in Yii?
Bizley
(Bizley)
September 11, 2014, 10:55am
9
Bootstrap style:
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: normal;
line-height: 1.42857;
margin-bottom: 0;
padding: 6px 12px;
text-align: center;
vertical-align: middle;
white-space: nowrap;
background-color: #000;
color: #fff;
text-decoration: none;
Create a css class with the above and use it on link.
sohel
(Tambadiyasohel)
March 30, 2015, 9:46am
10
please use this below its looking like button
<?php echo CHtml::link('ExportAll',array('user/exportall'),array('class'=>'btn yellow btn-sm','style'=>'float:right')); ?>