Give ID to submit button - cakephp-2.0

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! =)

Related

Big red cancel button on a cakephp form

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\''
));

Form element array cakephp

I am in need of all the arrays and subarrays for a form element. When referred cookbook,
I found only the subarrays for limited elements.
For example,
<?php
echo $this->Form->input('name', array(
'div' => array(
'id' => 'mainDiv',
'title' => 'Div Title',
'style' => 'display:block'
)
));
?>
Here in this form helper, we can get only arrays like id, title, style.But I am in need of all the possible array keys for form elements. How can we get this?
You can set common properties of any form while creating it like below which will be applicable for all form elements
echo $this->Form->create('my_form', , array(
'inputDefaults' => array(
'label' => false,
'div' => false
));
Now the label and div will not appear to any form element you gonna use, This is how you can create common set of array for all form element under it..
Hope this will help u

Is it possible to create a checkbox with images along with the text in the labels in cakephp?

Somebody please give me ideas on this!I would like to generate multiple checkboxes with an image along with the text in the label. I have created a field called solutioncheckbox in the Contact form for Checkbox. My code is as below for creating multiple Checkboxes
<?php echo $this->Form>input('solutioncheckbox',array('label'=>false,'type'=>'select','class'=>'solution','multiple'=>'checkbox','options'=>array(1=>'WEB DESIGN',2=>'WEB DEVELOPMENT',3=>'GRAPHICS DESIGN'))) ;?>
Can I create an image along with the text in each of the labels like WEB DESIGN,WEB DEVELOPMENT etc in my form
This will get the job done for you ;)
echo $this->Form->input
(
'Model.field',
array
(
'multiple' => 'checkbox',
'options' => array('1' => $this->Html->image('cake.icon.png') . 'Text beside the image', '2' => $this->Html->image('test-error-icon.png') . 'Other text beside the image'),
'escape' => FALSE
)
);

CakePHP: How to use HTML entities in button titles using Form Helper

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">&#x2713;</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.

Multiple checkboxes in CakePHP - how to set which are checked?

I have multiple checkboxes in CakePHP's Add/Edit view, created with:
echo $this->Form->input('email_warning_chb', array('type'=>'select', 'multiple'=>'checkbox', 'label'=> __('Email notice'), 'class'=>'multiple-chb', 'options'=> array('title...'=>array( '5'=>'5 days', '15'=>'15 days', '30'=>'30 days', '60'=>'60 days');
My question is how to set which one are checked by default (ie. in thi example, 5, 15 and 60)?
Thank you in advance!
As said in other answers, you should set the 'selected' option.
What some people don't mention is that your selected array should only contain the id in each element.
Example:
$selectedWarnings = $this->Warning->find('list', array(
'fields' => array('id')
));
echo $this->Form->input('email_warning_chb', array(
'label' => 'Email Notice',
'type' => 'select',
'multiple' => 'checkbox',
'options' => $warnings,
'selected' => $selectedWarnings
));
this looks like this one
cakephp: How to set checkbox to checked?
where $selected contains the selected values
in your controller you have to put the value like this:
$this->request->data['Model']['email_warning_chb'] = array(5,15,60);
and it will automatically display checkbox as selected.
Please ask if not work for you.

Resources