<?php
$options = array(
'infant' => '1',
'mater' => '2',
'prees' => '3',
'kinder' => '4', );
echo form_open('evals/proc_group');
echo form_checkbox('edu_level[]','1', in_array('1', $educational_levels)); echo form_label ('Infantes', 'infant', array ('class' => 'checkbox_label'));
echo form_checkbox('edu_level[]','2', in_array('2', $educational_levels)); echo form_label ('Maternales', 'mater', array ('class' => 'checkbox_label'));
echo form_checkbox('edu_level[]','3', in_array('3', $educational_levels)); echo form_label ('Preescolares', 'prees', array ('class' => 'checkbox_label'));
echo form_checkbox('edu_level[]','4', in_array('4', $educational_levels)); echo form_label ('Kindergarten', 'kinder', array ('class' => 'checkbox_label')); ?>
<input type="hidden" name="eval_id" value="<?php echo $evaluation->id ?>" />
<div class="clear"></div>
<?php echo form_submit('mysubmit','Guardar Grupo'); ?>
<div class="clear"></div>
<?php echo form_close(); ?>
<div class="clear"></div>
I need the checkboxes stay checked when i press Guardar Grupo. What can i do?
Hope this will work, I haven't checked the code myself.
var checkboxes = $('.checkbox_label');
for ( i = 0 ; i < checkboxes.length; i++ ) {
checkboxes[i].prop('checked', true)
}
You have to add this to the form's submit button click event.
Do a print_r($educational_levels) to see if the array contains the values or not. Other than that I can't see anything unusual. Also make sure that this $educational_levels is a single dimentional array.
This works perfectly for me:
public function index()
{
//$this->load->view('welcome_message');
$this->load->helper('form');
$educational_levels = array('1', '3');
echo form_checkbox('edu_level[]','1', in_array('1', $educational_levels));
}
You need to check if your array $educational_levels contains values and is not empty!.
Related
Based on search a form wiill be displayed with data based on search . I want to update this data with a button on the search result page. the update doesn't work and when I use var dump null values are returned
please help me out
view:
<h3> Allowances: </h3>
<div class='panel panel-info'>
<div class='panel panel-heading'></div>
<?php foreach ($allowance as $data): ?>
<div class="form-group">
<?php echo form_label( $data->name); ?>
<?php echo form_input(['class' => 'form-control', 'name' => 'amount','value' => $data->amount]); ?>
<?php echo form_hidden(['class' => 'form-control', 'name' => 'emp','value' => $data->emp_id]); ?>
<?php echo form_hidden(['class' => 'form-control', 'name' => 'comp','value' => $data->comp_id]); ?>
</div>
<?php endforeach; ?>
</div>
<a href='<?php echo base_url('payroll/update') ?>' class="btn btn-primary" type='submit'> Update</a>
COntroller
public function update(){
$emp_id = $this->input->get('emp');
$comp_id =$this->input->get('comp');
$d = [
'amount' =>$this->input->post('amount')
];
$this->payroll_model->update($d,$emp_id,$comp_id);
var_dump($d);
$this->session->set_flashdata('success','Successfully updated');
}
model
public function update($d,$emp_id,$comp_id){
// $array = array('emp_id'=>$emp_id,'comp_id' =>$comp_id);
// $this->db->where($array);
$this->db->where('emp_id',$emp_id);
$this->db->where('comp_id',$comp_id);
$this->db->update('emp_sal',$d);
return true;
enter code here
enter code here
enter code here
The reason why you are getting null values returned is that the line below redirects to the link in href instead of posting user's inputs
<a href='<?php echo base_url('payroll/update') ?>' class="btn btn-primary" type='submit'> Update</a>
To overcome this issue, use a form tag with action attribute that has the value of
base_url('payroll/update')
Such as the following
<?php echo form_open(base_url('payroll/update'), array('method'=>'post')) ; ?>
Replace the a tags you are using with the following input that submits user values instead of just redirecting with null values
<input class="btn btn-primary" type='submit'> Update</input>
I am populating data from database to radio button and want to check the first value as default but I have no idea on how to do it. Here is my coding that I've done so far.
View
<?php if($designThemes != null){; ?>
<?php foreach ($designThemes as $designTheme) { ?>
<?php
$designThemesValue = (set_value('theme_name') ? set_value('theme_name') : $designTheme['slug_url']);
$designThemesAttr = array(
'name' => 'designThemes',
'value' => $designThemesValue,
);
?>
<div class="col-md-4 col-sm-4">
<div class="radio custom-radio">
<label>
<?php echo form_radio($designThemesAttr); ?>
<span class="fa fa-circle"></span> <?php echo $designTheme['theme_name'] ?>
</label>
</div>
</div>
<?php }}; ?>
If I add 'checked' => TRUE in $designThemesAttr = array() the system will check the last value of radio button as the default, but I wanted to check the first value.
solved your issue you can set it by conditional statement as replace your code by this
<?php if($designThemes != null){; ?>
<?php $i=1;foreach ($designThemes as $designTheme) { ?>
<?php
$designThemesValue = (set_value('theme_name') ? set_value('theme_name') : $designTheme['slug_url']);
$designThemesAttr = array(
'name' => 'designThemes',
'value' => $designThemesValue,
);
if($i==1){
$designThemesAttr['checked'] = TRUE;
}
?>
<div class="col-md-4 col-sm-4">
<div class="radio custom-radio">
<label>
<?php echo form_radio($designThemesAttr); ?>
<span class="fa fa-circle"></span> <?php echo $designTheme['theme_name'] ?>
</label>
</div>
</div>
<?php $i++; }}; ?>
'checked' => TRUE in $designThemesAttr = array() the system will check the last value of radio button as the default. This is right, because you doing it inside a for loop, and only one radio remains selected inside a group. So the last one is showing checked.
So maintain a variable to count the iteration like:
$count = 1;
if( $count = 1; )
{
// use 'checked' => TRUE here
$count++; // The value is incremented so that the if condition can't run again. This will add 'checked' => TRUE to first radio only.
}
I got 3 array's where from i make 2 select box and a checkbox. What i want to do is that when i change CMS the checkbox value needs to change like in the array.
if i choose Joomla in the select box then i want the checkbox that is made with the $aOnderdelen, then in the array $aOnderdelen i have an array with Contact-form Foto-gallery and Carousel and this 3 have an array with the name of each CMS with different values and this are the values that the checkbox needs to get when you choose one of those and the CMS.
Example: i choose Joomla and i choose a Contact-formulier than contact-formulier checbox gets 3 as value.
$aCMS = array('SilverbeeCMS','Joomla','WP','Drupal','Scott');
$prijsPerUur=1;
$basisPrijs=
array(
array('titel' => 'Kopie', 'uur' => '8'),
array('titel' => 'Maatwerk', 'uur' => '10'),
array('titel' => 'Aangekocht', 'uur' => '12'),
array('titel' => 'Custom', 'uur' => '14')
);
$aOnderdelen = array
(
'Contact-formulier' => array
(
'SilverbeeCMS'=>3,
'WP'=>2,
'Joomla'=>3,
'Drupal'=>4,
'Scott'=> 5
),
'Foto-gallery' => array
(
'SilverbeeCMS'=>1,
'WP' => 3,
'Joomla'=> 4,
'Drupal'=> 5,
'Scott'=> 6
),
'Carousel' => array
(
'SilverbeeCMS'=>1,
'WP' => 4,
'Joomla'=> 5,
'Drupal'=> 6,
'Scott'=> 7
)
);
?>
This is the HTML form where the Select and checkbox are
<form action="" method="post">
<select id="cms" class="form-control" name="cms">
<?php foreach($aCMS as $key => $value): ?>
<option value="<?php echo strtolower($aCMS[$key]); ?>">
<?php echo $aCMS[$key]; ?>
</option>
<?php endforeach; ?>
</select>
<label><?php echo $template.$verplicht; ?></label>
<select id="templates" class="form-control" name="templates">
<?php foreach($basisPrijs as $key => $value): ?>
<option value="<?php echo $basisPrijs[$key]["uur"]; ?>">
<?php echo $basisPrijs[$key]["titel"]; ?>
</option>
<?php endforeach; ?>
</select>
<?php echo $oTitel; ?>
<div class="checkbox col-xs-12">
<div class="row">
<?php foreach($aCMS as $cmsKey => $cmsValue) ?>
<?php foreach($aOnderdelen as $key => $value):
foreach($value as $key1 => $value1)
{};
$i++;
echo "<div class='checkbox'>
<label><input class='check".$i."' type='checkbox' value='".strtolower($key)."' name='".$key."'>".$key."</label></div>"
;endforeach;?>
</div>
</div>
</form>
You have to use jquery along with AJAX for changing things dynamically
Simple example as
$(document).ready(function() {
$('#selector').change(function() {
//do here things required about changing
//You can also change DOM elements according to needs
//and have Ajax requests
})
});
I found how to do it
switch($("option:selected").val())
{
case "silverbeecms":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["SilverbeeCMS"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["SilverbeeCMS"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["SilverbeeCMS"] ?>)
break;
case "joomla":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["Joomla"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["Joomla"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["Joomla"] ?>)
break;
case "wp":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["WP"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["WP"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["WP"] ?>)
break;
case "drupal":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["Drupal"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["Drupal"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["Drupal"] ?>)
break;
case "scott":
$(".check1").val(<?php echo $aOnderdelen["Contact-formulier"]["Scott"] ?>)
$(".check2").val(<?php echo $aOnderdelen["Foto-gallery"]["Scott"] ?>)
$(".check3").val(<?php echo $aOnderdelen["Carousel"]["Scott"] ?>)
break;
}
New Answer more Flexibel
First Loop through the PHP array.
<?PHP
foreach($aCMS as $cmsKey => $cmsValue)
?>
<?php
foreach($aOnderdelen as $key => $value)
:
foreach($value as $key1 => $value1){};
?>
Than use data attr to get the prices.
<input class="<?php echo strtolower($key);?>" type="checkbox" value="<?php echo strtolower($key)?>" name="<?php echo $key;?>" data-silverbeecms="<?php echo $value['SilverbeeCMS']; ?>" data-wp="<?php echo $value['WP'];?>" data-joomla="<?php echo $value['Joomla'];?>" data-drupal="<?php echo $value['Drupal'];?>" data-scott="<?php echo $value['Scott'];?>">
After you get the Price in the data you can call this data from JQUERY and do the Match.
urenOnderdelen = 0;
$("#sCms, #templates, .contact-formulier, .foto-gallery, .carousel").change(function()
{
urenOnderdelen = 0;
urenTemplate = $("#templates").val();
$(".contact-formulier, .foto-gallery, .carousel").each(function()
{
if(this.checked)
{
urenOnderdelen+=parseInt($(this).data($("option:selected").val()));
}
});
$("#output, #output1, #gVoor").hide().fadeIn(300);
urenTemplate = $("#templates").val();
urenTemplate = parseInt(urenTemplate);
urenOnderdelen = parseInt(urenOnderdelen);
totaal = urenOnderdelen + urenTemplate;
$("#output").text(euroTeken + totaal*prijs);
});
I read the book "Yii", I can't understand how to look at the global _POST array receiving by controller?
VIEW
_form.php
<div class="row">
<?php
echo $form->labelEx($model,'category_id');
echo CHtml::DropDownList('Page[category_id]','', Category::allCategory(),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('subcategory/dynamicSubCategories'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#Page_subcategory_id', //selector to update
// 'data'=>array('category_id'=>'js:this.value'),
//leave out the data key to pass all form values through
)));
echo $form->error($model,'category_id');
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model,'subcategory_id');
echo CHtml::dropDownList('Page[subcategory_id]','', array());
echo $form->error($model,'subcategory_id');
?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
SubcategoryController.php
public function actionDynamicSubCategories() {
$data = Subcategory::model()->findAllByAttributes(array('category_id' => $_POST['category_id']));
$data = CHtml::listData($data, 'id', 'title');
foreach ($data as $value => $name) {
echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
}
}
I'm interested in value from view echo CHtml::DropDownList('Page[category_id]','', Category::allCategory(), ... which comes to the controller SubcategoryController.php?
At the top of your controller you can just output the $_POST array.
e.g.
print_r($_POST);
or
var_dump($_POST);
This should show you any post values.
To get your _POST variable in Yii, you can use var_dump(Yii::app()->request->post);
In my situation into the controller passed this _POST (Page['category_id']).
I use in controller:
$x = Yii::app()->request->getPost('Page');
$y = $x['category_id'];
$data = Subcategory::model()->findAllByAttributes(array('category_id' => (int)$y));
Solved!
I am trying to populate my dynamic dropdown menu using CI:
My issue is that when I set my dropdown value and text ($formImageCaptionDropDown = array($get_images['id'] => $get_images['description']);) it does not display - just displays a blank dropdown box.
I have done print_r on my $get_images so I know that this is working correct.
I also know that I am to use $var['value'] because I have copied the format of another page that uses the images model and is working fine.
I just cannot seem to populate the dropdown menu
I have the following code:
<?php
//Setting form attributes
$get_images = $this->image_model->getImages();
$formImageCaption = array('id' => 'imageCaption', 'name' => 'imageCaption');
$formImageCaptionDropDown = array($get_images['id'] => $get_images['description']);
$formImageCaptionSelection = array('id' => 'captionSelection', 'name' => 'captionSelection');
$formSubmit = array('id' => 'submit','name' => 'submit','value' => 'Edit Caption');
?>
<div id ="formLayout">
<?php echo form_open('admin/imagecaption',$formImageCaption);
echo form_fieldset();
?>
<p>Please Select A Caption Below To Edit: </p>
<?php echo form_label ('Caption:', 'caption');?>
<?php echo form_dropdown('caption', $formImageCaptionDropDown); ?>
<div id="errorCaption"><?php echo form_error('caption');?></div>
<span class="small">Required Field</span>
<?php echo form_fieldset_close();
echo form_close(); ?>
</div>
I have resolved my issue by doing the following:
I moved the line $get_images = $this->image_model->getImages(); into my controller as $data['$get_images'] = $this->image_model->getImages();
In my view I did the following:
<?php foreach ($get_images as $image){
echo '<option value="'.$image['id'].'">'.$image['description'].'</option>';
};
?>`