codeigniter form_dropdown with onChange don't work - php

No error but not working:
I need to set a four order choose of sports in gym, so i have to use four dropdown, i have te retrieve the list of data from database, it's an array drom database that containe 30 disciplines when i choose the fisrt one in the first dropdown the seconde dropdown musn't containe this value, and also when i choose a value from the 3rd dropdown this dropdown musn't containe value1 and value2 from dropdown1 and dropdown2, the same thing about the dropdown four it must containe only 27
My view :
<?php $sports = array(
'aucun choix' => ' Aucun choix',
'aerobic' => ' 01- Aerobic',
'musculation' => ' 02- Musculation',
'judo' => ' 03- Judo',
'taekwondo' => ' 04- Taekwando',
'aikido' => ' 05- Aikido',
'karaté' => ' 06- Karaté',
'haltérophilie' => ' 07- Haltérophilie',
'sport de salle' => ' 08- Sport de salle',
'sport feminin' => ' 09- Sport feminin',
'sport plein air' => ' 10- Sport plein air',
'sport de pêche' => ' 11- Sport de pêche',
'basketball' => ' 12- Basketball',
'hand-voley ball' => ' 13- Hand-voley ball',
'football' => ' 14- Football',
'pétanque' => ' 15- Pétanque',
'natation' => ' 16- Natation',
'jeux d\'echec' => ' 17- Jeux d\'echec',
'golf' => ' 18- Golf',
'cyclisme' => ' 19- Cyclisme',
'tenis' => ' 20- Tenis',
'equitation' => ' 21- Equitation',
'chasse tir vole' => ' 22- Chasse tir vole',
);
?>
<script>
function callSave(select) {
var parent = select.parentNode;
var usedValues = {};
for (var i = 0; i < parent.children.length; ++i) {
var s = parent.children[i];
if (s.nodeName.toLowerCase() != 'select') {
continue;
}
if (s.value != '') {
usedValues[ s.value ] = s;
}
}
for (var i = 0; i < parent.children.length; ++i) {
var s = parent.children[i];
if (s.nodeName.toLowerCase() != 'select') {
continue;
}
for (var j = 0; j < s.children.length; ++j) {
var o = s.children[j];
if (o.nodeName.toLowerCase() != 'option') {
continue;
}
var p = o.value == '' ? undefined : usedValues[o.value];
if (p == undefined || p == s) {
o.style.display = '';
}
else {
o.style.display = 'none';
}
}
}
}
</script>
<div <?php if(form_error('sport_ordre1')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
<label class="control-label">Sport ordre 1 :</label>
<div class="controls">
<?php echo form_dropdown('sport_ordre1', $sports , $this->input->post('sport_ordre1') ? $this->input->post('sport_ordre1') : $participant_sport->sport_ordre1 , 'onChange="callSave(this)"'); ?>
<span class="help-inline"><?php echo form_error('sport_ordre1'); ?></span>
</div>
</div>
<div <?php if(form_error('sport_ordre2')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
<label class="control-label">Sport ordre 2 :</label>
<div class="controls">
<?php echo form_dropdown('sport_ordre2', $sports , $this->input->post('sport_ordre2') ? $this->input->post('sport_ordre2') : $participant_sport->sport_ordre2 ,'onChange="callSave(this)"'); ?>
<span class="help-inline"><?php echo form_error('sport_ordre2'); ?></span>
</div>
</div>
<div <?php if(form_error('sport_ordre3')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
<label class="control-label">Sport ordre 3 :</label>
<div class="controls">
<?php echo form_dropdown('sport_ordre3', $sports , $this->input->post('sport_ordre3') ? $this->input->post('sport_ordre3') : $participant_sport->sport_ordre3 , 'onChange="callSave(this)"'); ?>
<span class="help-inline"><?php echo form_error('sport_ordre3'); ?></span>
</div>
</div>
<div <?php if(form_error('sport_ordre4')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
<label class="control-label">Sport ordre 4 :</label>
<div class="controls">
<?php echo form_dropdown('sport_ordre4', $sports , $this->input->post('sport_ordre4') ? $this->input->post('sport_ordre4') : $participant_sport->sport_ordre4 , 'onChange="callSave(this)"'); ?>
<span class="help-inline"><?php echo form_error('sport_ordre4'); ?></span>
</div>
</div>
the probleme is that when i select a value in one dropdown it apear on others, so the method onChange don't work for this case. Any help please ?

Well I think that you when you call .parentNode, you should access the DOM through its id.
As you didn't accessed it through id you have just pass the DOM element to the function.
'onChange="callSave(this.id)"';
but what actually do you need. You can use jquery.

Related

Having issues with hiding and showing divs on an onchange

I am having issues firing off an on-change in the department drop-down field not sure if i wrote it correctly. The error is Uncaught TypeError: Cannot read property 'style' of null. I am trying to select a department like claims then it will fire off an onchange to show another drop-down called workrequested. I have not filled all the departments yet but that should not mater if i want to test it on couple departments first. I think it has to do with dvPassport1.style.display
<script>
function ShowHideDiv1() {
var Department = document.getElementById("Department");
var divPassport1 = document.getElementById("divPassport1");
divPassport1.style.display = Department.value == "Claims" || Department.value == "Flat 1"|| Department.value == "Flat 2"|| Department.value == "Hanging Bulk" || Department.value == "Hanging Store North" || Department.value == "Hanging Store South" || Department.value == "Inventory Integrity" || Department.value == "Rack Shoes" || Department.value == "Fine Jewelry"? "block" : "none";
}
function ShowHideDiv2() {
var Department = document.getElementById("Department");
var divPassport2 = document.getElementById("divPassport2");
divPassport2.style.display = Department.value == "JackPotLane" ? "block" : "none";
}
</script>
<?=form_open('insert/create/', array(
'class' => 'form-horizontal',
'role' => 'form',
)); ?>
<div class="row">
<div class="container">
<h3>Validation Form</h3>
<br>
<div class="col-sm-6">
<div class="form-group">
<?php echo form_label('ZID', 'ZID', $attributes=array());?>
<?php echo form_input('ZID', set_value('ZID'), $attributes=array("class" => "form-control", "id"=>"ZID"));?>
<!--show error message -->
<div class="error"><?php echo form_error('ZID'); ?></div>
</div>
<div class="form-group">
<?php echo form_label('Employee Name', 'EmpName', $attributes=array());?>
<?php echo form_input('EmpName', set_value('EmpName'), $attributes=array("class" => "form-control", "id"=>"EmpName"));?>
<!--show error message -->
<div class="error"><?php echo form_error('EmpName'); ?></div>
</div>
<div class="form-group">
<?php echo form_label('Department', 'Department', $attributes=array());?>
<?php
$options = array(
""=>"Choose Department",
"Claims" => "Claims",
"Flat 1"=>"Flat 1");
?>
<?php echo form_dropdown('Department', $options,set_value('Department'),array("class" => "form-control", "id"=>"Department", "onchange" => "ShowHideDiv1();ShowHideDiv2();"));?>
<!--show error message -->
<div class="error"><?php echo form_error('Department'); ?></div>
</div>
<div class="form-group" id="divpassport1" style="display: none" >
<?php echo form_label('WorkRequested', 'WorkRequested', $attributes=array());?>
<?php
$options = array(
""=>"Choose WorkRequested",
"Cases Not Received" => "Cases Not Received",
"Master Pack"=>"Master Pack");
?>
<?php echo form_dropdown('WorkRequested', $options,set_value('WorkRequested'),array("class" => "form-control", "id"=>"WorkRequested"));?>
<!--show error message -->
<div class="error"><?php echo form_error('WorkRequested'); ?></div>
</div>
<div class="form-group" id="divpassport2" style="display: none" ">
<?php echo form_label('WorkRequested', 'WorkRequested', $attributes=array());?>
<?php
$options = array(
""=>"Choose jackpot WorkRequested",
"FYI" => "FYI",
"Request"=>"Request");
?>
<?php echo form_dropdown('WorkRequested', $options,set_value('WorkRequested'),array("class" => "form-control", "id"=>"WorkRequested"));?>
<!--show error message -->
<div class="error"><?php echo form_error('WorkRequested'); ?></div>
</div>
<div class="form-group">
<?php echo form_label('Description','ReqDescription', $attributes=array());?>
<?php echo form_textarea('ReqDescription',set_value('ReqDescription'),array("class"=>"form-control textarea","id"=>"ReqDescription"));?>
<!--show error ReqDescription -->
<div class="error"><?php echo form_error('ReqDescription'); ?></div>
</div>
<input type="hidden" name="DATEREQUESTED" value="<?php echo date("Y/m/d h:i:sa");?>" value="<?=set_value('DATEREQUESTED')?> " value="<?=set_value('DATEREQUESTED')?>">
<input type="hidden" class="form-control" id="Status" name="Status" value="Received" placeholder="Status" value="<?=set_value('Status')?>">
<div class="form-group">
<?php echo form_submit('submit', 'Submit', array("class"=>"btn-primary btn", "id"=>"submit"));?>
</div>
<?php echo form_close()?>
As far as I can see you want to get divPassport1 (divPassport1) and divPassport2 and not dvPassport1 and dvPassport2.
Change var dvPassport1 = document.getElementById("dvPassport1"); to var dvPassport1 = document.getElementById("divPassport1"); and second one respectively or correct the ids.
EDIT
I guess you are accessing elements too early and you DOM is not loaded yet. Move your js code to the end of page before closing body and wrap it following way to wait for window onload event:
<script>
(function() {
// your javascript code here
// the DOM will be available here
})();
</script>

Updating database based on checkbox Codeigniter

I'm trying to update a database column using a checkbox. The idea is that I want to only display certain things on the homepage, so the checkbox should send either 0 or 1 to the DB. If the record has 0 in the first page column, it shouldn't appear on the homepage, if it has 1 it should appear.
I tried setting something up, but it doesn't work as intended (it just refreshes the page with no effect)
The checkbox:
<?php echo form_checkbox(array('name' => 'first_page', 'class'=>'checkbox-inline', 'value' => 1)); ?>
Controller:
if(null != ($this->input->post('first_page'))) {
$first_page = 1;
$book_id= $this->input->post('id'); (the id is sent to the controller via an extra hidden input field)
$this->book_model->first_page($first_page, $book_id);
}
Model:
$this->db->set ( "first_page", $first_page);
$this->db->where ( "book_id", $book_id);
$this->db->update ( "books" );
return;
Full form:
<?php echo form_open('admin/modifica_autor'); ?>
<?php echo form_hidden('id', $item->id_carte); ?>
<?php echo form_hidden('id_autor', $item->id_autor)?>
<label for="titlu_nou">Titlu:</label>
<?php echo form_input(array('name' => 'titlu_nou_carte', 'class'=>'form-control', 'value' => $item->titlu)); ?> <br>
<label for="autor_nou">Autor:</label>
<select name='autor_nous' class="form-control"><?php
foreach ( $autori2 as $row ) {
echo '<option value="' . $row->id_autor . '">' . $row->nume_autor . '</option>'; }
?></select><br>
<label for="domeniu_nou">Domeniu:</label>
<select name='domeniu_nou' class="form-control"><?php
foreach ( $domenii as $row ) {
echo '<option value="' . $row->id_domeniu . '">' . $row->nume_domeniu . '</option>';
}
?></select><br>
<label for="pret_nou">Pret:</label>
<?php echo form_input(array('name' => 'pret_nou', 'class'=>'form-control', 'value' => $item->pret.' LEI')); ?><br>
<label for="descriere_noua">Descriere:</label>
<?php echo form_textarea(array('name' => 'descriere_noua', 'class'=>'form-control textarea', 'value' => $item->descriere)); ?><br>
<label for="prima_pagina">Afisare pe prima pagina:</label>
<?php echo form_checkbox(array('name' => 'prima_pagina', 'class'=>'checkbox-inline', 'value' => 1)); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<?php echo form_submit(array('name'=>'submit_autor','value' => 'Modifica', 'class'=>'btn btn-default')); ?>
<?php echo form_close(); ?>

PHP /AJAX - Update the list at any time when in MySQL appears a new row

i am trying to make an ajax call to my database and refresh my list that i display from database. Actually what i need is, i have a table with data and i display them using php, now i want to update my list on the page without refresh anytime when in my table is inserting a new row.
sample code
foreach($_IL_QUERY_INTERNAL as $_IL_RESULT_DATA){
echo $_IL_RESULT_DATA->il_name; //display all the name from my table
}
For example:
In my table i have 5 names and you can see them on the page, now somene subit a form and i insert the sixth name in my table, and i want to update my list with the sith name as real time with no refreshing.
I will appreciate any help.
My complete code
<?php
session_start();
wp_enqueue_style('il_style_mode');
wp_enqueue_style('il_admin_style_mode');
wp_enqueue_scripts('jquery');
global $_IL_ID;
global $_IL_LIMIT;
global $_IL_TOTAL;
global $wpdb;
$_IL_TABLE_NAME_INTERNAL = $wpdb->prefix . "il_internal_transfer";
$_SESSION['IL_COUNT_ADMIN'] = 1;
require_once ($_SERVER["DOCUMENT_ROOT"]."/wp-content/plugins/il_mt4_client_area/il_request/il_internal_transfer/il_internal_admin/il_internal_transfer_tabs.php");
$_IL_START = 0;
$_IL_LIMIT = 10;
if( isset($_GET['paged']) ){
$_IL_ID = $_GET['paged'];
$_IL_START = ($_IL_ID-1) * $_IL_LIMIT;
}
$_IL_QUERY_INTERNAL = $wpdb->get_results( "SELECT * FROM $_IL_TABLE_NAME_INTERNAL ORDER BY il_id DESC LIMIT $_IL_START, $_IL_LIMIT");
$_IL_NUM_ROWS_INTERNAL_ALL = $wpdb->get_var( "SELECT COUNT(*) FROM $_IL_TABLE_NAME_INTERNAL");
echo '<span class="il_admin_main_title">';
echo '<span>';
echo '<h2>Internal Transfers</h2>';
echo '</span>';
echo '<span>';
require_once ($_SERVER["DOCUMENT_ROOT"]."/wp-content/plugins/il_mt4_client_area/il_request/il_internal_transfer/il_internal_admin/il_internal_transfer_sub_tabs.php");
echo '</span>';
echo '</span>';
echo '<span class="il_admin_transactions_block" id="il_admin_transactions_block">';
echo '<ul id="list">';
if( $_IL_NUM_ROWS_INTERNAL_ALL < 1 ){
include ($_SERVER["DOCUMENT_ROOT"]."/wp-content/plugins/il_mt4_client_area/il_include/il_messages/il_internal_transfer_sorry.php");
}else{
foreach($_IL_QUERY_INTERNAL as $_IL_RESULT_DATA)
{
?>
<span class="il_admin_transactions_block_raw_block">
<form method="post">
<input type='hidden' name='il_transaction_id' value="<?php echo $_IL_RESULT_DATA->il_id ?>" />
<span class="il_admin_transactions_block_raw">
<span class="il_admin_transactions_block_raw_count"><?php echo $_SESSION['IL_COUNT_ADMIN'] ?></span>
<span class="il_admin_internal_block_raw_full_name">
<?php echo $_IL_RESULT_DATA->il_name ?>
</span>
<span class="il_admin_internal_block_raw_from_to">
<span><?php echo $_IL_RESULT_DATA->il_from_mt4 ?></span> <?php echo $_IL_RESULT_DATA->il_from_mt4_currency ?>
<img src="/wp-content/plugins/il_mt4_client_area/il_images/il_icons/il_gray_left_icon.png" class="il_arrow_between" />
<span><?php echo $_IL_RESULT_DATA->il_to_mt4 ?></span> <?php echo $_IL_RESULT_DATA->il_to_mt4_currency ?>
</span>
<span class="il_admin_internal_block_raw_email"><?php echo $_IL_RESULT_DATA->il_email ?></span>
<span class="il_admin_internal_block_raw_date"><?php echo $_IL_RESULT_DATA->il_date ?></span>
</span>
<span class="il_admin_transactions_block_raw_extras">
<?php if( $_IL_RESULT_DATA->il_comments === NULL || empty($_IL_RESULT_DATA->il_comments) ){ ?>
<?php } else { ?>
<span class="il_admin_transactions_block_raw_comment">
<span>Comment:</span>
<span><?php echo $_IL_RESULT_DATA->il_comments ?></span>
</span>
<?php } ?>
<?php if( $_IL_RESULT_DATA->il_status == 'approved' ){ ?>
<?php } else { ?>
<span class="il_admin_transactions_block_raw_extras_status_icon">
<img src="/wp-content/plugins/il_mt4_client_area/il_images/il_icons/il_green_status_<?php echo $_IL_RESULT_DATA->il_status ?>_icon.gif" alt="Processing" title="Processing"/>
</span>
<?php } ?>
<span class="il_admin_transactions_block_raw_extras_ip">
The transaction was done from this ip <?php echo $_IL_RESULT_DATA->il_user_ip ?>
</span>
<span class="il_admin_transactions_block_raw_extras_ip_select">
<?php if( $_IL_RESULT_DATA->il_status == 'approved' ){ ?>
<span class="il_admin_transactions_block_raw_extras_status_<?php echo $_IL_RESULT_DATA->il_status ?>"><?php echo $_IL_RESULT_DATA->il_status ?></span>
<img src="/wp-content/plugins/il_mt4_client_area/il_images/il_icons/il_green_status_<?php echo $_IL_RESULT_DATA->il_status ?>_icon.gif" alt="Processing" title="Processing" width="20"/>
<?php } else { ?>
<span class="il_admin_transactions_block_raw_extras_update">
<select name="il_status_new">
<option>approved</option>
<option>waiting</option>
<option>rejected</option>
</select>
</span>
<span class="il_admin_transactions_block_raw_extras_update_button">
<input type="submit" name="il_status_update" value="update status" />
<input type="submit" name="il_delete" value="delete" class="il_admin_transactions_delete_button" />
</span>
<?php } ?>
</span>
</span>
<span class="il_clear"></span>
</form>
</span>
<?php
$_SESSION['IL_COUNT_ADMIN']++;
}
}
echo '</ul>';
echo '</span>';
if(isset($_POST['il_status_update'])){
$wpdb->update(
$_IL_TABLE_NAME_INTERNAL,
array(
'il_status' => $_POST['il_status_new'],
),
array( 'il_id' => $_POST['il_transaction_id'] ),
array(
'%s',
),
array( '%s' )
);
};
if(isset($_POST['il_delete'])){
$wpdb->delete( $_IL_TABLE_NAME_INTERNAL, array( 'il_id' => $_POST['il_transaction_id'] ), array( '%d' ) );
};
$_IL_ROWS_COUNT = mysql_num_rows(mysql_query("select * from $_IL_TABLE_NAME_INTERNAL"));
$_IL_TOTAL = ceil( $_IL_ROWS_COUNT / $_IL_LIMIT );
if($_IL_LIMIT < $_IL_ROWS_COUNT){
echo '<span class="il_pagination_block_admin">';
if( $_IL_ID > 1 )
{
echo "<a href='?page=il_internal_transfer&tab=il_internal_transfer&paged=".($_IL_ID-1)."' class='il_pagination_prev'><span class='il_pagination_prev_icon'></span></a>";
}
echo "<ul class='il_pagination'>";
for( $i = 1; $i <= $_IL_TOTAL; $i++ )
{
if( $i == $_IL_ID ) { echo "<li class='il_pagination_current'>".$i."</li>"; }
else { echo "<li><a href='?page=il_internal_transfer&tab=il_internal_transfer&paged=".$i."'>".$i."</a></li>"; }
}
echo "</ul>";
if( $_IL_ID != $_IL_TOTAL )
{
echo "<a href='?page=il_internal_transfer&tab=il_internal_transfer&paged=".( $_IL_ID + 1 )."' class='il_pagination_next'><span class='il_pagination_next_icon'></span></a>";
}
echo "</span>";
}else{
}
?>
<script>
jQuery( document ).ready(function($) {
function fetch(){
$.ajax({
url: '/wp-content/plugins/il_mt4_client_area/il_request/il_internal_transfer/il_internal_admin/il_internal_transfer.php',
success: function(data) {
$(data).hide().prependTo("#list").slideDown("slow");
if($("#list li").length > 15){
$('#list li:gt(14)').remove();
}
setTimeout("fetch()", 5000);
}
});
}
});
</script>
Use this JS code for live updating your result. Code will append new result at the top.
JS CODE
function fetch(){
$.ajax({
url: 'PATH-TO_FILE',
success: function(data) {
$(data).hide().prependTo("#list").slideDown("slow");
if($("#list li").length > 15){
$('#list li:gt(14)').remove();
}
setTimeout("fetch()", 5000);
}
});
}
HTML CODE
<ul id="list">
<?php
foreach($_IL_QUERY_INTERNAL as $_IL_RESULT_DATA){
echo $_IL_RESULT_DATA->il_name; //display all the name from my table
}
?>
</ul>

Issuet with div's position - HTML PHP

I have a customer's list where is possible to tag each one like "Emprendedor", "Creativo" and/or "Detallista". I want to insert the following icon for no-taged customers:
http://imagizer.imageshack.us/v2/800x600q90/824/6h1d.png
The problem is the icon's position. I want it next to label. The code is:
<?php
foreach($customers as $customerKey => $customer){ ?>
<? $selectedCount = "0"; ?>
<div class="row customer customer-<?=$customer?>">
<div class="col-xs-6 col-md-4 customer-name customer-<?=$customer?>"><?=utf8_encode($customerNames[$customer])?></div>
<div class="col-xs-6 col-md-4"><?
foreach($tags as $tagKey => $tag){
$selected=false;
foreach($customerTags as $customerTagKey => $cTags)
if($customerTagKey == $customer)
foreach($cTags as $cKey => $cTag)
if($cTag == $tag){
$selected=true;
$selectedCount = $selectedCount + 1;
}
?><span class="label label-<?=$tag?><?=$selected?" selected":" hidden-print"?> customer-<?=$customer?>" onclick="connect('customer-<?=$customer?>', '<?=$customer?>', '<?=$tag?>');"><?=$tag?></span> <?
}?></div>
</div> <!-- customer-<?=$customer?> row -->
<?
echo "<div class=\"";
if($selectedCount == 0){
echo "glyphicon glyphicon-exclamation-sign glyphicon-red";
}
if($selectedCount > 1){
echo "glyphicon glyphicon-retweet glyphicon-blue";
}
echo " \"></div>";
}
?>

Codeigniter, i can't submit form values into database

I passed more than 4 hours seeking where is the error. but nothing found
My view inscriresalle.php :
<div class="widget-box">
<div class="widget-title">
<span class="icon">
<i class="icon-align-justify"></i>
</span>
<h5><?php echo empty($participant_salle->id) ? 'Nouveau Agent OCP:' : 'Modification de: ' . $participant_salle->nom.' '.$participant_salle->prenom; ?></h5>
</div>
<div class="widget-content nopadding">
<div class="form-horizontal" name="basic_validate" id="basic_validate" novalidate="novalidate">
<?php echo form_open(); ?>
<div <?php if(form_error('matricule')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Matricule :</label>
<div class="controls">
<?php echo form_input('matricule', set_value('matricule', $this->input->get('matricule'))); ?>
<span class="help-inline"><?php echo form_error('matricule'); ?></span>
</div>
</div>
<div <?php if(form_error('nom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Nom :</label>
<div class="controls">
<?php echo form_input('nom', set_value('nom', $this->input->get('nom'))); ?>
<span class="help-inline"><?php echo form_error('nom'); ?></span>
</div>
</div>
<div <?php if(form_error('prenom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Prénom :</label>
<div class="controls">
<?php echo form_input('prenom', set_value('prenom', $this->input->get('prenom'))); ?>
<span class="help-inline"><?php echo form_error('prenom'); ?></span>
</div>
</div>
<div <?php if(form_error('beneficiaire')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Bénéficiaire :</label>
<div class="controls">
<label><?php echo form_radio('beneficiaire', 'Agent', $this->input->get('beneficiaire') == 'Agent') ?> Agent </label>
<label><?php echo form_radio('beneficiaire', 'Conjoint', $this->input->get('beneficiaire') == 'Conjoint') ?> Conjoint </label>
<label><?php echo form_radio('beneficiaire', 'Enfant', $this->input->get('beneficiaire') == 'Enfant') ?> Enfant </label>
<span class="help-inline"><?php echo form_error('beneficiaire'); ?></span>
</div>
</div>
<div <?php if(form_error('sexe')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Sexe :</label>
<div class="controls">
<label><?php echo form_radio('sexe', 'M', $this->input->get('sexe') == 'M') ?> Masculin </label>
<label><?php echo form_radio('sexe', 'F', $this->input->get('sexe') == 'F') ?> Féminin </label>
<span class="help-inline"><?php echo form_error('sexe'); ?></span>
</div>
</div>
<div <?php if(form_error('date_naissance')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Date de Naissance :</label>
<div class="controls">
<input type="text" name="date_naissance" id="date1" value="<?php echo set_value('date_naissance', $this->input->get('dateNaissance')); ?>" />
<span class="help-inline"><?php echo form_error('date_naissance'); ?></span>
</div>
</div>
<div <?php if(form_error('telephone')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Téléphone :</label>
<div class="controls">
<?php echo form_input('telephone', set_value('telephone', $participant_salle->telephone)); ?>
<span class="help-inline"><?php echo form_error('telephone'); ?></span>
</div>
</div>
<div <?php if(form_error('date_inscription_salle')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Date inscription :</label>
<div class="controls">
<input type="text" name="date_inscription_salle" id="date2" value="<?php echo set_value('date_inscription_salle', $participant_salle->date_inscription_salle); ?>" />
<span class="help-inline"><?php echo form_error('date_inscription_salle'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_debut_periode')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Début période :</label>
<div class="controls">
<input type="text" name="salle_debut_periode" id="date3" value="<?php echo set_value('salle_debut_periode', $participant_salle->salle_debut_periode); ?>" />
<span class="help-inline"><?php echo form_error('salle_debut_periode'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_fin_periode')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Fin période :</label>
<div class="controls">
<input type="text" name="salle_fin_periode" id="date4" value="<?php echo set_value('salle_fin_periode', $participant_salle->salle_fin_periode); ?>" />
<span class="help-inline"><?php echo form_error('salle_fin_periode'); ?></span>
<span class="help-block">
</div>
</div>
<script type="text/javascript">// <![CDATA[
var qp = new Array();
var tarif = new Array();
var datestart = document.getElementById('date3');
var dateend = document.getElementById('date4');
$(document).ready(
// a chaque changement de discipline on obtien l'id du tableau discipline.
function(){
$('#country').change(function(){ //any select change on the dropdown with id country trigger this code
$("#cities > option").remove(); //first of all clear select items
var salle_nom = $('#country').val(); // here we are taking country id of the selected one.
$.ajax({
type: "POST",
url: "http://localhost/public_html/admin/dropdown_salle/get_cities/"+salle_nom, //here we are calling our user controller and get_cities method with the country_id
dataType : "json",
success: function(disciplines) //we're calling the response json array 'cities'
{
var discipline = new Array();
for (i=0; i<disciplines.length; ++i) {
// remplisage des 3 tableaux :discipline, tarif, et qp_agent
discipline[i] = disciplines[i].discipline+' pour '+disciplines[i].categorie_tarif;
qp[i] = disciplines[i].qp_agent;
tarif[i] = disciplines[i].tarif;
}
$.each(discipline,function(id,value) //here we're doing a foeach loop round each value with id as the key and value as the value
{
var opt = $('<option />'); // here we're creating a new select option with for each value
opt.val(id);
opt.text(value);
$('#cities').append(opt); //here we will append these new select options to a dropdown with the id 'cities'
});
}
});
});
function qp(qp, id) {
return qp[id];
}
function tarif(tarif, id) {
return tarif[id];
}
$('#cities').change(function () {
var a = $(this).find('option:selected').attr('value');
//here i retrieve the qp and tarif value corresponds to my 'discipline' choosen.
var qpValue = qp(qp, a);
var tarifValue = tarif(tarif, a);
var start = datestart.value;
var end = dateend.value;
var date1 = new Date(start);
var date2 = new Date(end);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
var diffMonths = Math.round(diffDays / 30);
alert('Vous avez Selectionnez '+diffMonths+' mois');
var finalresult = Math.round(diffMonths*qpValue*tarifValue);
document.getElementById("salle_montant_paye").value = finalresult;
});
});
// ]]>
</script>
<?php $countries['#'] = 'Aucun choix'; ?>
<?php
foreach ($countries as $k => $v) {
unset ($countries[$k]);
$new_key1 = $v;
$countries[$new_key1] = $v;
}
?>
<div <?php if(form_error('salle_nom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
<label class="control-label">Nom de la Salle :</label>
<div class="controls">
<?php echo form_dropdown('salle_nom', $countries , $this->input->post('salle_nom') ? $this->input->post('salle_nom') : $participant_salle->salle_nom , 'id="country"'); ?>
<span class="help-inline"><?php echo form_error('salle_nom'); ?></span>
</div>
</div>
<?php $cities['#'] = 'Aucun choix'; ?>
<div <?php if(form_error('salle_discipline')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
<label class="control-label">Discipline et type:</label>
<div class="controls">
<?php echo form_dropdown('salle_discipline', $cities , $this->input->post('salle_discipline') ? $this->input->post('salle_discipline') : $participant_salle->salle_discipline , 'id="cities"'); ?>
<span class="help-inline"><?php echo form_error('salle_discipline'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_montant_paye')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Montant à payé :</label>
<div class="controls">
<input type="text" name="salle_montant_paye" id="salle_montant_paye" value="<?php set_value('salle_montant_paye', $participant_salle->salle_montant_paye) ?> "></input>
<span class="help-inline"><?php echo form_error('salle_montant_paye'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_versement_espec')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Versement espéce :</label>
<div class="controls">
<?php echo form_input('salle_versement_espec', set_value('salle_versement_espec', $participant_salle->salle_versement_espec)); ?>
<span class="help-inline"><?php echo form_error('salle_versement_espec'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_versement_cheq')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Versement chèque :</label>
<div class="controls">
<?php echo form_input('salle_versement_cheq', set_value('salle_versement_cheq', $participant_salle->salle_versement_cheq)); ?>
<span class="help-inline"><?php echo form_error('salle_versement_cheq'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_numero_cheq')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Numéro de chèque :</label>
<div class="controls">
<?php echo form_input('salle_numero_cheq', set_value('salle_numero_cheq', $participant_salle->salle_numero_cheq)); ?>
<span class="help-inline"><?php echo form_error('salle_numero_cheq'); ?></span>
</div>
</div>
<div class="form-actions">
<?php echo form_submit('submit', 'Enregistrer', 'class="btn btn-success"'); ?>
</div>
<?php echo form_close();?>
</div>
</div>
</div>
</br>
My controller agent.php :
public function inscriresalle ($id = NULL) {
// Fetch a participant or set a new one
if ($id) {
$this->data['participant_salle'] = $this->participantsalle_m->get($id);
count($this->data['participant_salle']) || $this->data['errors'][] = 'Agent non trouvé';
}
else {
$this->data['participant_salle'] = $this->participantsalle_m->get_new();
}
$this->load->model('salle_m');
$this->data['countries'] = $this->salle_m->get_countries();
// Set up the form
$rules = $this->participantsalle_m->rules_participantsalle;
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE) {
$data = $this->participantsalle_m->array_from_post(array('matricule', 'nom', 'prenom', 'beneficiaire', 'sexe', 'telephone', 'date_naissance', 'date_inscription_salle', 'salle_debut_periode', 'salle_fin_periode', 'salle_montant_paye', 'salle_versement_espec', 'salle_versement_cheq', 'salle_numero_cheq'));
$this->participantsalle_m->save($data, $id);
redirect('admin/agent/profile/3608');
}
// Load the view
$this->data['subview'] = 'admin/agent/inscriresalle';
$this->load->view('admin/_layout_main', $this->data);
}
My model participantsalle_m.php :
<?php
class Participantsalle_M extends MY_Model
{
protected $_table_name = 'participants_salle';
protected $_order_by = 'id';
public $rules_participantsalle = array(
'matricule' => array(
'field' => 'matricule',
'label' => 'Matricule',
'rules' => 'trim|required|xss_clean'
),
'nom' => array(
'field' => 'nom',
'label' => 'Nom',
'rules' => 'trim|required|xss_clean'
),
'prenom' => array(
'field' => 'prenom',
'label' => 'Prénom',
'rules' => 'trim|required|xss_clean'
),
'beneficiaire' => array(
'field' => 'beneficiaire',
'label' => 'Bénéficiaire',
'rules' => 'trim|required|xss_clean'
),
'sexe' => array(
'field' => 'sexe',
'label' => 'Sexe',
'rules' => 'trim|required|xss_clean'
),
'telephone' => array(
'field' => 'telephone',
'label' => 'Téléphone',
'rules' => 'trim|xss_clean'
),
'date_naissance' => array(
'field' => 'date_naissance',
'label' => 'Date de naissance',
'rules' => 'trim|required|xss_clean'
),
'date_inscription_salle' => array(
'field' => 'date_inscription_salle',
'label' => 'Date inscription a la salle',
'rules' => 'trim|required|xss_clean'
),
'salle_debut_periode' => array(
'field' => 'salle_debut_periode',
'label' => 'Début période',
'rules' => 'trim|required|xss_clean'
),
'salle_fin_periode' => array(
'field' => 'salle_fin_periode',
'label' => 'Fin période',
'rules' => 'trim|required|xss_clean'
),
'salle_nom' => array(
'field' => 'salle_nom',
'label' => 'Nom de la salle',
'rules' => 'trim|required|xss_clean'
),
'salle_discipline' => array(
'field' => 'salle_discipline',
'label' => 'Discipline de la salle',
'rules' => 'trim|required|xss_clean'
),
'salle_montant_paye' => array(
'field' => 'salle_montant_paye',
'label' => 'Montant à payé',
'rules' => 'trim|required|xss_clean'
),
'salle_versement_espec' => array(
'field' => 'salle_versement_espec',
'label' => 'Versement éspece',
'rules' => 'trim|required|xss_clean'
),
'salle_versement_cheq' => array(
'field' => 'salle_versement_cheq',
'label' => 'Versement chèque',
'rules' => 'trim|required|xss_clean'
),
'salle_numero_cheq' => array(
'field' => 'salle_numero_cheq',
'label' => 'Numéro de chèque',
'rules' => 'trim|required|xss_clean'
),
);
public function get_new()
{
$participant_salle = new stdClass();
$participant_salle->matricule = '';
$participant_salle->nom = '';
$participant_salle->prenom = '';
$participant_salle->beneficiaire = '';
$participant_salle->sexe = '';
$participant_salle->telephone = '';
$participant_salle->date_naissance = '';
$participant_salle->date_inscription_salle = '';
$participant_salle->salle_debut_periode = '';
$participant_salle->salle_fin_periode = '';
$participant_salle->salle_nom = '';
$participant_salle->salle_discipline = '';
$participant_salle->salle_montant_paye = '';
$participant_salle->salle_versement_espec = '';
$participant_salle->salle_versement_cheq = '';
$participant_salle->salle_numero_cheq = '';
return $participant_salle;
}
function __construct ()
{
parent::__construct();
}
}
Everything seems to be good but i realy don't find error, why data don't saved on database.
My database structure is :
id
- nom
- prenom
- beneficiaire
- sexe
- telephone
- date_naissance
- date_inscription_salle
- salle_debut_periode
- salle_fin_periode
- salle_nom
- salle_discipline
- salle_montant_paye
- salle_versement_espec
- salle_versement_cheq
- salle_numero_cheq
Maybe it's not my day for coding, i don't see the probleme, Any help please?
the function save() on MY_Model :
public function save($data, $id = NULL){
// Set timestamps
if ($this->_timestamps == TRUE) {
$now = date('Y-m-d H:i:s');
$id || $data['created'] = $now;
$data['modified'] = $now;
}
// Insert
if ($id === NULL) {
!isset($data[$this->_primary_key]) || $data[$this->_primary_key] = NULL;
$this->db->set($data);
$this->db->insert($this->_table_name);
$id = $this->db->insert_id();
print_r($id);
}
// Update
else {
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->set($data);
$this->db->where($this->_primary_key, $id);
$this->db->update($this->_table_name);
}
return $id;
This line breaks it for me.
count($this->data['participant_salle']) || $this->data['errors'][] = 'Agent non trouvé';
try
if (empty($this->data['participant_salle'])){
$this->data['errors'][] = 'Agent non trouvé';
}

Categories