There is a form with normal:
$this->Form->create('Users');
$this->Form->input('name');
...
that ends in
$this->Form->end('Submit');
I want to add a cancel button next to it.
$this->Html->link('Cancel', array('controller' => 'users', 'action' => 'index'))
This produces a link but I want a button.
Is there a Cake PHP way of getting this done?
There's no pure Cake way to create such a button that I know of. I think it's easiest to use the button() method of the Form helper, adding a click event to the Cancel button and just end the form without any arguments in the end() method.
$this->Form->create('Users');
echo $this->Form->input('name');
echo $this->Form->button('Submit');
echo $this->Form->button('Cancel', array(
'type' => 'button',
'onclick' => 'location.href=\'/users\''
));
echo $this->Form->end();
You can add a button like this:
$this->Form->input("", array("type"=>"button", "name" => "Cancel"));
You can add any html button attribute in the array that's in 2nd param of input.
or
$this->Form->button(
'Click me',
array()
)
);
For that you need to remove $this->Form->end('Submit'); and instead of this use this:
$this->Form->submit('Submit'); //the submit button
// put the button code i mentioned above
$this->Form->end(); // and then for closing form tag
See This link for more detail
You can make use of bootstrap button classes "btn btn-danger" for this purpose.
echo $this->Form->button('Cancel', array(
'type' => 'button',
'class' => 'btn btn-danger',
'onclick' => 'location.href=\'/users\''
));
Related
I am new in cakephp and in my layout I wanna use this code...
Home<span style="font-size:16px;" class="pull-right hidden-xs"></span>
how can I use Html helper to rewrite it?
for example like this code :
echo $this->Html->link('Home',['controller'=>'users','action'=>'home']); instead that.
Adding the 'escape'=>false option to your link makes it so it doesn't try to translate ('escape') all your html characters.
echo $this->Html->link(
$this->Html->tag('span', 'Home', array(
'class' => 'pull-right hidden-xs',
'style' => 'font-size:16px;'
)
)
, '#'
, array(
'escape' => false // Notice Here
)
);
I am trying to transfer a value automatically from selection input area to another input area when the selection input has changed. But I cannot. Please help me. The code is here:
<?php
echo $this->Form->input('treatment',
array('options' => $types, 'id' => 'treatment_foo'));
echo $this->Form->input('fee', array('id' => 'fee_foo'');
echo $this->Js->get('#treatment_foo')->event('change',
$this->Js->request(
array(
'update' => '#fee_foo',
'dataExpression' => true,
'data' => '10'))
);
?>
Just use some JQuery
$(document).ready(function() {
$('#treatment_foo').change(function() {
$('#fee_foo').val($('#treatment_foo').val());
});
});
I'd like to use a checkmark as the text for a button. The entity I want is ✓ but when I put that in as the text for the button using the Form Helper, it always converts the leading ampersand into & so that the text shows but not the entity.
Here's how I'm creating the button:
echo $this->Form->button(
'✓',
array(
'type' => 'submit',
'id' => $checklistItem['ChecklistItem']['id'],
'escape' => 'false'
)
);
and the generated HTML looks like this:
<button type="submit" id="1">✓</button>
which obviously doesn't render the entity.
I've tried it by setting 'escape' => 'true' but that has not effect at all.
Any ideas?
You do not need to escape it false, it is by default escaped to false.
echo $this->Form->button('✓',
array(
'type' => 'submit',
'id' => $checklistItem['ChecklistItem']['id']
)
);
You need to move your escape to the third element of the button:
echo $this->Form->button(
'✓',
array(
'type' => 'submit',
'id' => $checklistItem['ChecklistItem']['id'],
),
array('escape' => 'false')
);
Also, this has already been answered here.
I want to use Radio Button using the Form Helper. A radio button has a Radio element and a Label. I have by default Display: block for Label element. I want to assign a class the the label of the Radio button so that i can assign it a inline-block.
$attributes = array('legend' => false, 'label' => array('class' => 'radioBtn'));
echo $this->Form->radio('gender', $options, $attributes);
How can i assign a class to the label of the option
By looking at the Form->radio() method code, nothing seems related to attributes belonging to the labels.
But to modify the display of these labels, you could use a surrounding div
echo '<div class="inline_labels">';
echo $this->Form->radio('gender', $options, $attributes);
echo '</div>';
and use CSS like this:
.inline_labels label
{
display: inline-block;
}
How about using FormHelper::label(string $fieldName, string $text, array $options)
You could define the label class in the options array, so (for example):
echo $options = array( /* relevant stuff goes here */ );
echo $attributes = array( /* relevant stuff goes here */ );
echo $this->Form->radio('gender', $options, $attributes);
echo $this->Form->label('gender', 'Text of your label', array('label'=>'radioBtn'))
Source CakePHP Cookbook on FormHelper
Work for me:
// Add your own label with CSS class
$opts = array('1' => "<label class='myCSS'>My first option</label>", "2" => "<label class='myCSS'>My second option</label>");
// Put label param to false
echo $this->Form->input('my-input', array('type' => 'radio', 'label' => false, 'options' => $opts, 'legend' => false));
Enjoy
I have a form and i have ended it using,
echo $this->Form->end('Login');
However, i can't seem to assign it an id or class to style it and be able to reference it with jquery. Also,I want to style it with a picture and the picture has the text already in so i need the buttons value to be empty but i can't manage that either...
Any Help?
Many Thanks, Chris
***Note - this is the html it generates;
<div class="submit"><input type="submit" value="Login"/></div>
Ideally i would like to remove the div aswell but its not a necessity.
here's the solution:
$options = array
(
'label' => 'Update',
'value' => 'Update!',
'id' => 'blabla',
'div' => array(
'class' => 'glass-pill',
)
);
echo $this->Form->end($options);
Cheers! =)