I have a page with a search function and I want to keep the values selected this way if I want to make another search I don't have to refill all the inputs.
Those are my inputs that i want to keep the value:
<?= $this->Form->input('search', ['placeholder' => 'Search', 'label' => false]); ?>
<input type="radio" name="multimedia_type_id" id="radio1" value="1">
<input type="radio" name="multimedia_type_id" id="radio2" value="2">
<input type="radio" name="multimedia_type_id" id="radio3" value="3">
<?= $this->Form->input('category_id', ['class' => 'electdown',
'label' => false,
'empty' => 'Categories',
'default' => 'Categories',
'options' => $categories
]); ?>
how can I keep the values?
Related
I'm a new user of CakePHP.
I'm trying to add some div to contain my input + my label.
This is what I've got :
<?php
$option = array ("value1" => "labelContent1", "value2" => "abelContent2");
echo $this->Form->input('name', array('type' => 'radio', 'options' => $option, 'div' => true, "legend" => false));
?>
<div class="input radio">
<input type="hidden" name="data[Quiz][name]" id="ModelName_" value=""/>
<input type="radio" name="data[Quiz][name]" id="ModelName1" value="value1" />
<label for="ModelName1">labelContent1</label>
<input type="radio" name="data[Quiz][name]" id="ModelName2" value="value2" />
<label for="ModelName2">labelContent2</label>
</div>
And this what I would like to have :
<div class="input radio">
<input type="hidden" name="data[Quiz][name]" id="ModelName_" value=""/>
<div>
<input type="radio" name="data[Quiz][name]" id="ModelName1" value="value1" />
<label for="ModelName1">labelContent1</label>
</div>
<div>
<input type="radio" name="data[Quiz][name]" id="ModelName2" value="value2" />
<label for="ModelName2">labelContent2</label>
</div>
</div>
Do you know if it is possible to make it by using the FormHelper ?
I know it's an old thread but I had to reply.
The correct way to achieve this without creating a bad mark-up is to use before and after options:
echo $this->Form->input('name', array( 'type' => 'radio',
'separator'=> '</div><div>',
'before' => '<div>',
'after' => '</div>',
'options' => $option,
'label' => true,
"legend" => false
)
);
It looks like you can't achieve that with the Form Helper. The radio options are not wrapped in anything. See code.
You can add 'separator' => '<br/>' to the Form->input options, to display each option in its own line.
or implement it yourself.
you can try this
$option = array ("value1" => "labelContent1", "value2" => "abelContent2");
echo $this->Form->input('name', array( 'type' => 'radio',
'separator'=> '</div><div>',
'options' => $option,
'label' => true,
"legend" => false
)
);
<?php
$option = array ("value1" => "labelContent1", "value2" => "abelContent2");
echo $this->Form->input('name', array(
'type' => 'radio',
'options' => $option,
'templates' => ['radioWrapper' => '<div>{{label}}</div>'],
"legend" => false));
?>
This seems to work well for Cake 3.+
I am trying to add below style..
<div class="rowElem noborder">
<label>Language:</label>
<div class="formRight noSearch">
<select name="select2" class="chzn-select">
<option value="opt1">Choose the Language</option>
<option value="opt2" selected="selected">Kannada</option>
<option value="opt3">Telugu</option>
<option value="opt4">Tamil</option>
</select>
</div>
<div class="fix"></div>
</div>
But in cakephp, I have this code
<?php echo $this->Form->input('language_id', array('class' => 'chzn-select' )); ?>
Please give me the solution..
If I understand what you are asking, this is what you need to do.
In your controller you will create your options array for the select box:
$this->set('languageOptions', array('opt1' => 'Choose Language', 'opt2' => 'Kannada', 'opt3' => 'Telugu', 'opt4' => 'Tamil'));
Then in the view, you create the form:
<div class="rowElem noborder">
<label for="language_id">Language:</label>
<?php echo $this->Form->input('language_id', array('class' => 'chzn-select', 'options' => $languageOptions, 'label' => false, 'div' => array('class' => 'formRight noSearch'))); ?>
<div class="fix"></div>
</div>
$langs = array('opt1' => 'Choose Language', 'opt2' => 'Kannada', 'opt3' => 'Telugu', 'opt4' => 'Tamil');
$this->set(compact('langs')); // if you set options from controller
Then in view try this:
$this->Form->input('language_id', array(
'type' => 'select',
'options' => $langs,
'selected' => 2 // suppose default select Kannada
)
);
Cake Php Select Option Code
Language:
Form->input('language_id', array('class' => 'chzn-select', 'options' => $languageOptions, 'label' => false, 'div' => array('class' => 'formRight noSearch'))); ?>
i'm trying to get a checkbox with his label
echo $this->Form->checkbox('straordinari', array('div'=>'true', 'label' => 'Straordinari'));
in browser i get
<input id="ReportStraordinari_" type="hidden" value="0" name="data[Report][straordinari]">
<input id="ReportStraordinari" type="checkbox" value="1" label="Straordinari" div="true" name="data[Report][straordinari]">
but there is no label
where is the problem?
You should get what you are looking for with the following:
echo $this->Form->input('straordinari', array('type' => 'checkbox'));
I using :
<?php
echo $this->Form->input('coupDeCoeur',
array('div' => false,
'label' => false,
'type' => 'checkbox',
'before' => '<label class="checkbox">',
'after' => '<i></i>coupDeCoeur</label>'
));
?>
I'm new in cakephp. What I try to accomplish is this output :
<p><label> </label><input class="adminbut rad2" type="submit" name="submit" value="Login" /></p>
And this is what I did in my view file
<?php echo $this->Form->end(array(
'div' => false,
'label' => 'Login',
'class' => 'adminbut rad2',
'name' => 'submit',
'value' => 'Login',
'before' => '<p>',
'after' => '</p>'
));?>
And what I got is :
<input class="adminbut rad2" name="submit" value="Login" type="submit" /></p>
And as you can see, my output is missing :
<label> </label>
Any solution?
Thanks :)
Try
$form->create();
$form->submit("Login",array( 'div' => false, 'class' => 'adminbut rad2', 'name' => 'submit', 'value' => 'Login', 'before' => '<p><label> </label>', 'after'
=> '</p>'
));
$form->end();
echo $form->input('submit', array(
'type'=>'submit',
'value'=>'Login',
'class'=>'adminbut rad2',
'div'=>array('tag'=>'p'),
'label'=>" "
));
Try This my friend
Cakephp 2.X
$this->Form->submit(__('Submit'), array('class'=>'adminbut rad2'));
Cakephp 1.x
$form->submit(__('Submit'), array('class'=>'adminbut rad2'));
I am using a Form helper in CakePHP. like
echo $form->input('field', array(
'type' => 'radio','legend'=>$r['Attribute']['label'],
// 'after' => '--after--',
// 'between' => '--between---',
'separator' => '--separator--',
'options' => array('1', '2')
));
which generates me as
<div class="input radio">
<fieldset>
<legend>Gender</legend>
<input type="hidden" value="" id="field_" name="data[field]"/>
<input type="radio" value="0" id="Field0" name="data[field]"/>
<label for="Field0">1</label>--separator--
<input type="radio" value="1" id="Field1" name="data[field]"/>
<label for="Field1">2</label>
</fieldset>
</div>
Is there any way to keep my options that i have received from my Database instead of 1,2
where i tried it with receving my options using
<?php foreach ($viewfields as $r): ?>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function($){
$("#"+<?=$r['Attribute']['id'];?>).each(function() {
type= "<?=$r['Attribute']['type'];?>";
if(type=="radio")
{
var ht = $.ajax({
type: "GET",
url: "http://localhost/FormBuilder/index.php/forms/viewChoices/"+attribute_id,
async: false
}).responseText;
var myObject = eval('(' + ht + ')');
var data = myObject;var j=0;
$.map(data.choices, function(i){ j++;
alert(i.choice);//which alerts as male and female correctly.
return i.choice;});
}
});//each
});
alert(i.choice); alerts the options correctly ..
How to keep these options in the array() of the Form Helper so that to get these options male and female instead of default 1,2
Please suggest me..
Place the options in a key => value array - as shown here : Cake Options
echo $form->input('field', array(
'type' => 'radio',
'legend' => $r['Attribute']['label'],
'separator' => '--separator--',
'options' => array('Male' => 'male', 'Female' => 'female')
));
See how you go.