I'm creating a form and want to use multiple fieldsets and legends, is this possible using the form helper?
My form so far -
echo $this->Form->create('PatientCase');
echo $this->Form->inputs(array(
'legend' => 'Patient Details',
...
));
echo $this->Form->end('Save Patient Case');
If you use Form::inputs(), CakePHP will automatically wrap the fields in a fieldset:
echo $this->Form->inputs(array(
'legend'=>'Login',
'User.username',
'User.password'
));
Will produce:
<fieldset>
<legend>Login</legend>
<div class='input text'>...</div>
<div class='input password'>...</div>
</fieldset>
if you set 'fieldset'=>false in your inputs array, cake will suppress field fieldset markup.
You can also use (as also suggested by #kical) before and after to insert the fieldset markup - this makes your code a little less intuative:
echo $this->Form->input('User.username', array(
'before'=>'<fieldset><legend>Login</legend>'
));
echo $this->Form->input('User.password', array(
'after'=>'</fieldset>'
));
You can also manually insert the fieldset markup (handy if you want to customise the fieldset markup or create fieldsets within fieldsets:
<fieldset>
<legend>Login</legend>
<?php
echo $this->Form->input('User.username');
echo $this->Form->input('User.password');
?>
</fieldset>
See API: http://api.cakephp.org/class/form-helper#method-FormHelperinput
Mainly params like: before, after, between or just format
Related
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
)
);
I'm using the Form helper to generate a label:
$this->Form->label('Contact.name', 'Name');
Which generates the following:
<label for="ContactName">Name</label>
Is it possible to generate the following using the helper:
<label for="ContactName"><span class="mandatory">*</span> Name</label>
Whilst I can manually write the html for the above it becomes a little more difficult when I am using the input method where a label is automatically generated.
For example:
$this->Form->input('Contact.forename',array('div' =>false,
'label' => array(
text'=> 'First Name',class =>'myclass'),
'class' => 'input','size' => '25' ,'tabindex' => '1'));
Is this possible in cake or do I have to manually inject the html using javascript when the page loads? Which I would think is rather ugly.
If you are using model validation for the mandatory fields then cakephp automatically applies '*' on the Label else you can use the helper as follows-
echo $this->Form->label('name', '<span class="mandatory">*</span> Name');
If you don't want the labels to generate automatically you can use "label => false" while using the helper.
echo $this->Form->input('Contact.forename',array('label' =>false));
Not sure CakePHP supports that (and it would get a bit messy anyway). The simplest solution I can think of is to assign a "mandatory" class to the label via the form helper:
$this->Form->label('User.name', 'Your username', array('class'=>'mandatory'));
Which produces something like:
<label class="mandatory" for="ContactName">Name</label>
Then the rest is done purely in CSS:
label.mandatory:after {
content: ' *';
color: red;
display: inline;
}
Avoids having any additional HTML.
I know this is old, but maybe someone with Cakephp 3 is having the same problem. This is what fixed it for me, without any inlinecode.
<?php
echo $this->Form->input(
'renovate_old',
[
'type' => 'checkbox',
'label' => ['text' => __('Alte Wohnung'), 'class' => 'moCheckLabel']
]); ?>
So you can name your label and use the Databasefield to write.
you can do it simple by
echo $this->Form->input('whatever', array('between'=>'<label for="ContactName"><span class="mandatory">*</span> Name</label>','label'=>false));
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! =)
Hey all,
I'm making a booking calendar for a rental house and I'm trying to make a selectable calendar update two form fields after selection. I want users to be able to drag across available days and populate the start and end date of my form. This is what I have so far:
<script type='text/javascript'>
$(document).ready(function() {
$('#calendar').fullCalendar({
events: "bookings/feed",
selectable: true,
unselectAuto: false,
select: function(startDate, endDate, allDay, jsEvent, view) {
**I just don't know what to put here to edit the inputs bolded below**
}
});
});
</script>
<div style="width: 500px;"><div id="calendar"></div></div>
<div id="eventdata"></div>
<div id="form">
<?php echo $form->create('Booking'); ?>
**<?php echo $form->input('start', array( 'label' => 'Check In:', 'type' =>'text')); ?>
<?php echo $form->input('end', array( 'label' => 'Check Out:', 'type' =>'text')); ?>**
<?php echo $form->input('firstName'); ?>
<?php echo $form->input('lastName'); ?>
</div>
Cheers!
Solved! The following passes the Start and End dates to the form.
select: function(startDate, endDate) {
$( '#BookingStart' ).val(startDate)
$( '#BookingEnd' ).val(endDate)
}
The code in your question didn't paste correctly, but in general to change the input value in jQuery you can do $( '#id_name' ).val( 'new value' ). CakePHP assigns form field ids with the pattern ModelField so the ids you need should be "BookingStart" and "BookingEnd" (you can verify by looking at the HTML source). You can also give the fields any id you want with 'id' => 'foo' option.