Individual class option for radio buttons - forms

Is there an individual class option for radio buttons in Cake 2.x?
In my opinion the logical approach would be like:
<div class="input radio required">
<?php
$options = array(
array('1' => 'Kuchen', 'class' => 'cake'),
array('2' => 'Kekse', 'class' => 'biscuits'),
array('3' => 'Eis', 'class' => 'iceCream'),
);
$attributes = array(
'legend' => false,
'default' => '1'
);
echo $this->Form->radio('INCOMETYPE', $options, $attributes);
?>
</div>
But that doesn´t work. I hope you can help. Thanks :)

You could extend FormHelper to add implement this functionality if you intend to use it elsewhere. If it's a one off, you might be better to produce the markup by hand. Use the code produced by $this->Form->radio to give you a start.

Related

Yii2 make an input field appear only in create

I would like to make an input field appear only in the 'create' form and not in the 'update' form. How can I achieve this?
You can do that by following way
if ($model->isNewRecord){
echo $form->field($model, 'password')->passwordInput(['maxlength' => true, 'placeholder' => "Enter password"]);
}
You can use $model->isNewRecord in many creative ways that can help you do some stuff depending on create/update.
i.e.
Hide a field
if ($model->isNewRecord){
echo $form->field($model, 'title')->textInput()
}
Change a style, class or property like readonly
$isEditable = (model->isNewRecord);
$class = (model->isNewRecord)?'class-a':'class-b';
echo $form->field($model, 'title')->textInput([
'readonly'=>$isEditable,
'disabled' => $isEditable,
'class'=>$class])
Changing a label
Html::submitButton( ($model->isNewRecord)
?'Create'
:'Update',
['class' => 'btn btn-success','id' => 'submit-btn',]);
Show a different button
echo ($model->isNewRecord)
? Html::a('Cancel', ['index'], ['class' => 'btn btn-warning'])
: Html::a('Close', ['otherplace'], ['class' => 'btn btn-primary']);
You can play a lot with $model->isNewRecord and actually modify some stuff depending on the state.
And many other stuff.

How to add a class in li-Tag of a menu?

I seem to be blind, stupid or both but I can't add own classes to li-items of a menu. Here are multiple tries:
<?php
$options = array(
'items' => 'menu1', //menu to be displayed
'class' => 'own-class-test-1',
'css' => array(
'class' => 'own-class-test-2',
),
'active' => 'own-active-test-2',
'attributes' => array(
'id' => 'ipsTest',
'class' => 'nav nav-pills pull-right'
)
);
echo ipSlot('menu', $options); ?>
Can anybody help me with this? I am only able to change the preset like active-class. Adding classes to the ul works without problems.
Thank you & cheers,
Thomas
I've check the code. Currently you can modify <li> only through variable defined here - https://www.impresspages.org/docs/navigation
There's no "default" things to add extra class for all <li>. However, if it selects every tag then what's the point adding it? Add required styles directly through CSS.

Disable autocomplete in CakePHP form input box

I am creating form inputs with the CakePHP Form helper and some inputs (Most of the time 'username' and 'password') are being autocompleted on create actions, login actions, etc.. this is annoying. I am guessing those are just more common so the browser is using its cookies to try to complete the inputs.
Anyways.. how do I disable this?
In my view:
...
echo $this->Form->input('username', array(
'label' => 'Please enter your username',
'class' => 'pure-u-1-2'
));
echo $this->Form->input('password', array(
'label' => 'Please enter your password',
'class' => 'pure-u-1-2'
));
...
What am I missing?
You can specify attributes to be sent to the form helper. Specify the attribute 'autocomplete' and set its value to 'off'.
...
echo $this->Form->input('username', array(
'label' => 'Please enter your username',
'class' => 'pure-u-1-2',
'autocomplete' => 'off'
));
echo $this->Form->input('password', array(
'label' => 'Please enter your password',
'class' => 'pure-u-1-2',
'autocomplete' => 'off'
));
...
Which results in something like this for your HTML:
<input name="data[Model][username]" autocomplete="off" class="pure-u-1-2" id="ModelUsername" type="text">
You may also do this on the whole form instead of just each input. Just specify the same attribute and value in the form create like so:
...
echo $this->Form->create('Model', array(
'class' => 'class',
'autocomplete' => 'off'
));
This will give you something like this in your HTML:
<form action=".../Model/Action" class="class" autocomplete="off" id="ModelActionForm" method="post" accept-charset="utf-8">
NOTE Several browsers will now ignore autocomplete="off" or autocomplete="false". The workaround is to place a hidden text and password field before all other inputs on your form. The browsers will fill those instead of the ones you want to leave alone.
The best solution is to use autocomplete = new-password
It works great in Chrome and Firefox
Like this:
$this->Form->input('password', array('type' => 'password', 'autocomplete' => 'new-password'));

Turn off pluralization of class names in cakephp

How to Turn off pluralization altogether in cakephp2.2
This is the source code of my page:
<form action="/scores/exam2014s/aview" id="exam2014AviewForm" method="post" accept-charset="utf-8">
In the above code suffix - 's' in 'exam2014s' is appearing automatically, which i dont want kindly help how to avoide the pluralization of the above.
In the bootstrap.php, I have used the following code enter code hereto turnoff pluralization:
Inflector::rules(
'plural',
array(
'rules' => array('/^([a-zA-Z_-]*)$/i' => '\1'),
'irregular' => array(),
'uninflected' => array()
)
);
With the above code in bootstrap I could not fix the problem.
Code in my index.ctp is below:
echo $this->Form->create('exam2014', array('action' => 'aview'));
echo $this->Form->label('Page.name','Name: ',null);
echo $this->Form->input('qr_code');
echo $this->Form->submit();
echo $this->Form->end();
Thanks in advance.
Sai Krishna
why not simply the following code?
echo $this->Form->create(
'exam2014',
array(
'url' => array('controller' => 'exam2014', 'action' => 'aview')
)
)
Since Cake2.x the form posts to itself by default.
So simply do:
echo $this->Form->create('Exam2014');

how to add form id in cakephp when creating a form

i am new in cakephp so i dont know how can i do this ..
i want to add custom form id in my form but it is not adding the id ..it is using the default one adding the 'UserIndexForm' id..
how can i add this id
i want to do like this
<form method="post" action="#" id="form-login">
here cakephp code
<?php
echo $this->Form->create('User', array(
'inputDefaults' => array(
'label' => false,
'div' => false,
'id' =>'form-login'//not working
)
));
?>
please help me if anyone know this
thankyou in advance
The inputDefaults option is only changing the input fields so you need to set the id on the root level of the array:
<?php
echo $this->Form->create('User', array(
'id' => 'form-login',
'inputDefaults' => array(
'label' => false,
'div' => false
)
));
?>