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é';
}
Related
I am in the learning stage in php.Please help me with my update form.Advanced thanks. I have a form to update any user information with a button "Save" and "Reset" button.I update any information the version number increase.But the problem is when i do not update any information and click on "Save" button the version number increases.It should not increase.I am giving my Controller and form code....
public function actionCreate()
{
$model=new CvUpload;
$model2=new CvUpload;
$UserType=new UserType;
$CvHistory=new CvHistory;
$this->performAjaxValidation($model);
if(!empty($_POST))
{
$id = $_POST['CvUpload']['user_id'];
$cv_type = $_POST['CvUpload']['cv_type'];
$criteria = new CDbCriteria();
$criteria->condition = "user_id = $id AND is_current='yes' AND cv_type='$cv_type'";
$CvUploadmodel = CvUpload::model()->find($criteria);
if(!empty($CvUploadmodel))
{
$CvUploadmodel->is_current='no';
$CvUploadmodel->status='inactive';
if($CvUploadmodel->save(false)){
$model->attributes=$_POST['CvUpload'];
$model->upload_date = new CDbExpression("NOW()");
$model->update_date = new CDbExpression("NOW()");
$model->version_id = $CvUploadmodel->version_id+1;
if($model->save(false))
{
$CvHistory->cv_id = $model->cv_id;
$CvHistory->user_id = $model->user_id;
$CvHistory->job_title_id = $model->job_title_id;
$CvHistory->cv_type = $model->cv_type;
$CvHistory->version_id = $model->version_id;
$CvHistory->file_name = $model->file_name;
$CvHistory->upload_date = $model->upload_date;
$CvHistory->update_date = $model->update_date;
$CvHistory->is_current = $model->is_current;
$CvHistory->status = $model->status;
if($CvHistory->save(false))
{
$this->redirect(array('view','id'=>$model->cv_id));
}
}
}
}
else
{
$model->attributes=$_POST['CvUpload'];
$model->upload_date = new CDbExpression("NOW()");
$model->update_date = new CDbExpression("NOW()");
$model->version_id=1;
if($model->save())
{
$CvHistory->cv_id = $model->cv_id;
$CvHistory->user_id = $model->user_id;
$CvHistory->job_title_id = $model->job_title_id;
$CvHistory->cv_type = $model->cv_type;
$CvHistory->version_id = $model->version_id;
$CvHistory->file_name = $model->file_name;
$CvHistory->upload_date = $model->upload_date;
$CvHistory->update_date = $model->update_date;
$CvHistory->is_current = $model->is_current;
$CvHistory->status = $model->status;
if($CvHistory->save(false))
{
$this->redirect(array('view','id'=>$model->cv_id));
}
}
}
}
$this->render('create',array(
'model'=>$model,
'UserType'=>$UserType,
'CvHistory'=>$CvHistory,
));
}
public function actionUpdate($id)
{
$model=$this->loadModel($id);
$CvHistory=new CvHistory;
if(isset($_POST['CvUpload']))
{
$model->attributes=$_POST['CvUpload'];
if($model->save())
{
$criteria = new CDbCriteria();
$criteria->condition = "cv_id = $model->cv_id AND is_current = 'yes'";
$CvHistory = CvHistory::model()->find($criteria);
$CvHistory->is_current = 'no';
$CvHistory->status = 'inactive';
if($CvHistory->save(false))
{
$new_CvHistory=new CvHistory;
$new_CvHistory->cv_id = $model->cv_id;
$new_CvHistory->user_id = $model->user_id;
$new_CvHistory->job_title_id = $model->job_title_id;
$new_CvHistory->cv_type = $model->cv_type;
$new_CvHistory->version_id = $CvHistory->version_id+1;
$model->version_id = $new_CvHistory->version_id ;
$new_CvHistory->file_name = $model->file_name;
$new_CvHistory->upload_date = $model->upload_date;
$new_CvHistory->update_date = new CDbExpression("NOW()");
$model->update_date = $new_CvHistory->update_date ;
$new_CvHistory->status = $model->status;
$new_CvHistory->is_current = "yes";
$new_CvHistory->save(false);
$model->save(false);
if($new_CvHistory->save(false))$this->redirect(array('view','id'=>$model->cv_id));
}
}
}
$this->render('update',array(
'model'=>$model,
'CvHistory'=>$CvHistory,
));
}
MY form button code:
<style>
#type {
background-color:#f5f5f5;
font-family: 'Arial';
font-size: 20px;
text-decoration: none;
color:#b2b2b2;
border:none;
float: right;
}
div.form label {
display: block;
font-size: 1em;
font-weight: bold;
}
.types-add{
float: right;
}
#type:hover {
border: none;
}
</style>
<?php if (Yii::app()->user->hasFlash('created')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('created'); ?>
</div>
<?php endif; ?>
<div class="form">
<?php $form=$this->beginWidget(
'booster.widgets.TbActiveForm',
array(
'id'=>'CvUpload-form',
'type' => 'horizontal',
'htmlOptions' => array(
'class' => 'well',
'enctype' => 'multipart/form-data',
)
));
?>
<fieldset>
<h1 align="center">CV Upload</h1>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php
$criteria=new CDbCriteria();
echo $form->dropDownListGroup(
$model,
'user_id',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(User::model()->findAll($criteria), 'id', 'user_id'),
'dataProvider'=>$model->searchByUserId(Yii::app()->user->getId()),
'htmlOptions' => array('prompt'=>'Select'),
)
)
); ?>
</div>
<div class="row" id="jobTitle">
<?php
$criteria = new CDbCriteria;
$criteria->condition = "status= 'active'";
echo $form->dropDownListGroup(
$model,
'job_title_id',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(JobTitle::model()->findAll($criteria), 'id', 'name'),
'htmlOptions' => array('prompt'=>'Select job title'),
)
)
); ?>
</div>
<?php echo CHtml::form($this->createUrl('uploadreport'), 'post', array('enctype'=>'multipart/form-data'));?>
<label class="col-sm-3 control-label required" for="CvUpload_file_name">
Upload File
</label>
<div class="row" id="file_upload" style="margin-left:20%; margin-bottom:2%;">
<?php
$this->widget('CMultiFileUpload',array(
'name' => 'files',
'accept' => 'doc|docx|pdf',
'max' => 1,
'htmlOptions' => array('size' => 25),
));
echo CHtml::htmlButton('Upload',array(
'onclick'=>'javascript: send();', // on submit call JS send() function
'id'=> 'post-submit-btn', // button id 'newcreate'
'class'=>'btn btn-primary',
));
?>
</div>
<?php Yii::app()->clientScript->registerCoreScript("jquery"); ?>
<script src="http://code.jquery.com/jquery-migrate-1.2.0.js"></script>
<script>
function send(){
var formData = new FormData($("#CvUpload-form")[0]);
$.ajax({
url: '<?php echo Yii::app()->createUrl("CvUpload/upload"); ?>',
type: 'POST',
data: formData,
datatype:'json',
beforeSend: function() {
},
success: function (data) {
$("#CvUpload_file_name").val(data);
},
complete: function() {
},
error: function (data) {
alert("There may a error on uploading. Try again later");
},
cache: false,
contentType: false,
processData: false
});
return false;
}
</script>
<div class="row" id="file_name">
<?php echo $form->textFieldGroup(
$model,'file_name',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
)
);
?>
</div>
<div class="row" id="statustype">
<?php
$status = array('active'=>'Active', 'inactive'=>'Inactive');
echo $form->dropDownListGroup(
$model,
'status',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => $status,
'htmlOptions' => array('prompt'=>'Select a status'),
)
)
); ?>
</div>
<div class="row" id="statustype">
<?php
$is_current = array('yes'=>'Yes', 'no'=>'No');
echo $form->dropDownListGroup(
$model,
'is_current',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => $is_current,
'htmlOptions' => array('prompt'=>'Select a status'),
)
)
); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array(
'class'=>'btn btn-primary',
'style'=>"position:relative; margin-left:25%",
'id'=> 'yt1', // button id
)); ?>
</div>
</fieldset>
<?php $this->endWidget(); ?>
</div><!-- form -->
<!--/*/*
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'cv-upload-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'user_id'); ?>
<?php echo $form->textField($model,'user_id',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model,'user_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'upload_date');enter code here ?>
<?php echo $form->textField($model,'upload_date'); ?>
<?php echo $form->error($model,'upload_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'file_name'); ?>
<?php echo $form->textField($model,'file_name',array('size'=>60,'maxlength'=>150)); ?>
<?php echo $form->error($model,'file_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'file_location'); ?>
<?php echo $form->textField($model,'file_location',array('size'=>60,'maxlength'=>150)); ?>
<?php echo $form->error($model,'file_location'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
If you don't change form values, it doesn't mean that this data wouldn't be sended to server.
Here at least button save will sended, so this case will always true:
if(!empty($_POST))
You didn't show whole form, but I suggest that fields user_id and cv_type has values (no mater values where changed or not, if form has fields they will be submited)
$id = $_POST['CvUpload']['user_id'];
$cv_type = $_POST['CvUpload']['cv_type'];
That's why model $CvUploadmodel = CvUpload::model()->find($criteria); loads and increament version_id
This is my code in actionCheckout():
public function actionCheckout() {
$proInfo = Yii::app()->session['cart'];
if (Yii::app()->user->isGuest) {
$model = new Payment;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Payment'])) {
$model->attributes = $_POST['Payment'];
$model->thoigian = date('Y-m-d H:i:s');
if ($model->save()) {
foreach ($proInfo as $key => $value) {
$order = new Order;
$order->id_sp = $key;
$order->soluong = $value;
$product = Product::model()->findByPK($key);
if (empty($product->khuyenmai)) {
$price = $product->gia_sp;
} else {
$price = ceil($product->gia_sp * (100 - $product->khuyenmai) / 100 / 1000) * 1000;
}
$order->thanhtien = $price * $value;
$order->id_payment = $model->id_hoadon;
$order->save();
}
unset(Yii::app()->session['cart']);
$this->redirect(Yii::app()->request->baseUrl . '/cart/success/' . $model->id_hoadon);
}
}
$this->render('checkout', array(
'cart' => $proInfo,
'model' => $model,
));
} else {
$model = new Payment;
$user = User::model()->findByPk(Yii::app()->user->id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Payment'])) {
$model->attributes = $_POST['Payment'];
$model->id_user = Yii::app()->user->id;
$model->hoten = $user->hoten;
$model->email = $user->email;
$model->dienthoai = $user->dienthoai;
$model->diachi = $user->dia_chi;
$model->thoigian = date('Y-m-d H:i:s');
$model->xuly = "Chưa xử lý";
if ($model->save()) {
foreach ($proInfo as $key => $value) {
$order = new Order;
$order->id_sp = $key;
$order->soluong = $value;
$product = Product::model()->findByPK($key);
if (empty($product->khuyenmai)) {
$price = $product->gia_sp;
} else {
$price = ceil($product->gia_sp * (100 - $product->khuyenmai) / 100 / 1000) * 1000;
}
$order->thanhtien = $price * $value;
$order->id_payment = $model->id_hoadon;
$order->save();
}
unset(Yii::app()->session['cart']);
$this->redirect(Yii::app()->request->baseUrl . '/cart/success/' . $model->id_hoadon);
}
}
$this->render('checkout', array(
'user' => $user,
'cart' => $proInfo,
'model' => $model,
));
}
}
And this is my "checkout.php" file in views:
<link rel="stylesheet" type="text/css" href="<?= Yii::app()->request->baseUrl ?>/css/cart.css"/>
<?php
$this->breadcrumbs = array(
'Giỏ hàng' => array('cart/index'),
'Thanh toán'
);
$this->pageTitle = "Thanh Toán";
$items = 0;
$total = 0;
$i = 0;
?>
<h1>Thanh toán</h1>
<?php
if (empty($cart)) {
echo "<p>Bạn chưa có sản phẩm nào trong giỏ hàng</p>";
} else {
$form = $this->beginWidget('CActiveForm', array(
'id' => 'payment-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => false,
));
?>
<div class="payment">
<?php
if (!Yii::app()->user->isGuest) {
?>
<div class="paymentCustomer">
<h3>Thông tin thanh toán</h3>
<div style="padding: 10px; clear:both; float:left">Họ tên:<?= Yii::app()->user->name ?></div>
<div style="padding: 10px; clear:both; float:left">Email:<?= $user->email ?></div>
<div style="padding: 10px; clear:both; float:left">Địa chỉ:<?= $user->dia_chi ?></div>
<div style="padding: 10px; clear:both; float:left">Điện thoại:<?= $user->dienthoai ?></div>
</div>
<?php
} else {
?>
<div class="paymentCustomer">
<h3>Thông tin thanh toán</h3>
<div class="inputUser"><div>Họ tên <span>*</span></div><?php echo $form->textField($model, 'hoten', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'hoten'); ?>
<div class="inputUser"><div>Email <span>*</span></div><?php echo $form->textField($model, 'email', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'email'); ?>
<div class="inputUser"><div>Địa chỉ <span>*</span></div><?php echo $form->textField($model, 'diachi', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'diachi'); ?>
<div class="inputUser"><div>Điện thoại <span>*</span></div><?php echo $form->textField($model, 'dienthoai', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'dienthoai'); ?>
</div>
<?php
}
?>
<div class="paymentCustomer">
<h3>Hình thức thanh toán</h3>
<p class="paymentYour">
<?php
echo $form->radioButtonList($model, 'phuongthuc', array(
'Tại Cửa hàng' => 'Thanh toán tại cửa hàng',
'Khi Nhận hàng' => 'Thanh toán khi nhận được hàng',
'Tài khoản Ngân hàng' => 'Thanh toán qua tài khoản Ngân hàng'
), array("class" => "myCheck"));
?>
<?php echo $form->error($model, 'phuongthuc'); ?>
</p>
<h3 style="margin: 50px 0 5px 0;">Mã khuyến mãi</h3>
<?php echo $form->textField($model, 'coupon', array('class' => "inputText loginText")); ?>
<?php echo $form->error($model, 'coupon'); ?>
</div>
</div>
<div class="cartInfo">
<div class="headCart">
<div class="cartField1">Mã sản phẩm</div>
<div class="cartField2">Tên sản phẩm</div>
<div class="cartField3">Đơn giá</div>
<div class="cartField3">Số lượng</div>
<div class="cartField3">Thành tiền</div>
</div>
<?php
foreach ($cart as $key => $value) {
$product = Product::model()->findByPK($key);
if (empty($product->khuyenmai)) {
$price = $product->gia_sp;
} else {
$price = ceil($product->gia_sp * (100 - $product->khuyenmai) / 100 / 1000) * 1000;
}
?>
<div class="bodyCart">
<div class="cartField1" data-label="Mã sản phẩm"><?= $product->ma_sp ?></div>
<div class="cartField2" data-label="Tên sản phẩm"><span><?= $product->ten_sp ?></span></div>
<div class="cartField3" data-label="Đơn giá"><?= $price . "đ" ?></div>
<div class="cartField3" data-label="Số lượng"><?= $value ?></div>
<div class="cartField3" data-label="Thành tiền"><?= $price * $value . "đ" ?></div>
</div>
<?php
$items +=$value;
$total +=$price * $value;
}
?>
<div class="footCart">
<div class="cartField1">Tổng cộng</div>
<div class="cartField2"></div>
<div class="cartField3"><?= $items ?></div>
<div class="cartField3"><?= $total . "đ" ?></div>
</div>
</div>
<div>
<a href="<?= Yii::app()->request->urlReferrer ?>">
<input type="button" class="cartLeftButton button" value="Quay trở lại"/>
</a>
<?php echo CHtml::submitButton('Xác nhận và gửi đơn hàng', array("class" => "cartRightButton button")); ?>
</div>
<?php
$this->endWidget();
}
?>
But when submit that form it not direct to success page. I have try to insert die("abc") to each line in Controller and find out that it not run from the line
if($model->save()){....
How can I fix that now?
Hi, I'm trying to validate active filefield fields that were created in Yii so dynamic.
I build using a forech for this inputs, the question is that when trying to validate when the user selects an image, indicate whether the file you chose is above the allowed weight, and also if it is a correct file format.
But i don't know that I'm doing wrong.
I tried this:
My model
public $image;
public function tableName() {
return 'vrf_image';
}
/**
* #return array validation rules for model attributes.
*/
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id_form', 'numerical', 'integerOnly'=>true),
// Pruebas para subir imagen
// Inicio
array(
'image',
'file',
'types'=>'jpg, gif, png',
'allowEmpty'=>true,
'on'=>'update',
'on'=>'insert',
'wrongType'=>'Solo imagenes',
'mimeTypes' => 'image/gif, image/jpeg, image/png',
'wrongMimeType' => 'Invalid mime type',
'maxSize'=>1024*1024*2,
'tooLarge'=>'File has to be smaller than 2MB',
),
array(
'image',
'length',
'max'=>50,
'on'=>'insert,update'
),
array(
'id, image, id_form, id_ques',
'safe',
'on'=>'search'
),
// Fin
);
}
My views
<div class="container-fluid">
<div class="row paddings_bottom">
<?php
$hoho = VrfImage::model()->findAll("id_form = $search->id");
$formImage=$this->beginWidget('CActiveForm', array(
'id'=>'verification-form-image',
'action' => Yii::app()->createUrl("backendVerification/default/CreateImage?id=".$modUser->id),
'htmlOptions' => array('enctype' => 'multipart/form-data'),
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>true,
'validateOnType'=>true,
),
));
?>
<div class="col-md-12 col-lg-12">
<table class="table table-bordered" style="margin-bottom: 0;">
<?php
$oo = 0; $ban = 0;
foreach ($numQues as $ii => $NQ){
if($ii==0){
echo '<div class="borTopFormVrf"><span class="White">Company Documentation</span></div>';
}
if($ii <6){
if($oo<2){
if($oo==0){
echo '<tr>';
}
?>
<td class="col-md-6 col-lg-6 nopadd" style="border: 1px solid #000;">
<?php
foreach ($hoho as $key => $value) {
if($hoho[$key]->id_ques == $NQ){
echo '<img src="'.getThemeUri().'/../../VerificationResource/images/'.$hoho[$key]->image.'" style="max-width:100%;">';
$ban = 1;
}
}
if($ban!=1){ echo '<img src="#" style="max-width:100%; visibility: hidden;" id="img_prev'.$ii.'" alt="your image"/>'; }
else{ $ban=0; }
?>
<?php echo $form->HiddenField($modImage,"[".$ii."]id_ques",array('value'=>$NQ)); ?>
<?php echo $formImage->fileField($modImage,'['.$ii.']image', array('class'=>'form-control Borf-c', 'onChange'=>'readURL(this,'.$ii.')')); ?>
<?php echo $formImage->error($modImage,'['.$ii.']image'); ?>
<div class="text-center">
<?php echo $nameQues[$ii]; ?>
</div>
</td>
<?php if($oo==1){ echo '</tr>'; $oo = -1; }
$oo++;
}}
}
?>
</table>
</div>
<div class="col-md-12 col-lg-12">
<div class="col-md-12 col-lg-12 divTopFormBVrf">
<?php
if(isset($search->id_verifier)){
if($search->id_verifier == userID()){
echo CHtml::submitButton('Save', array('class' => 'btn btn-success btn_create_address btn_create_address_size'));
}
}
?>
</div>
</div>
<?php $this->endWidget(); ?>
</div>
In my controller
public function actionCreateImage($id) {
$form = VrfForm::model()->find("id_user = $id");
$path_picture = realpath(Yii::app()->getBasePath()."/../VerificationResource/images")."/"; //ruta final de la imagen
if(isset($_POST['VrfImage'])) {
foreach ($_POST['VrfImage'] as $key => $value) {
$modImage = new VrfImage;
$modImage->attributes = $value;
//print_r($modImage->validate());
if($modImage->validate()){
echo 'Correcto';
////////////////////////////////////////////////////////////////////
$rnd = rand(0,9999); // generar números aleatorios entre 0-9999
$uploadedFile=CUploadedFile::getInstance($modImage,'['.$key.']image');
$fileName = "{$rnd}-{$uploadedFile}"; // número aleatorio + nombre de archivo, o se puede usar: $fileName=$uploadedFile->getName();
if(!empty($uploadedFile)) { // Compruebe si el archivo se ha subido o no.
$uploadedFile->saveAs($path_picture.$fileName);
$modImage->image = $fileName;
$modImage->id_ques = $value['id_ques'];
$modImage->id_form = $form->id;
if($modImage->save()) {
//echo ' REVISA!!! <br>';
}
else{
echo $modImage->error();
}
}
////////////////////////////////////////////////////////////////////
}
else{
echo 'Falla';
//$this->redirect($this->createUrl('default/Form'));
}
}
}
//$this->redirect(Yii::app()->user->returnUrl.'backendVerification/default/Form?id='.$id);
}
But don't It does not work.!!!
Is bad my "clientOptions" in the form?
Is bad my rules in the model?
Help T.T
Well, I knew not to use Yii to achieve validate my fields. It will not be the best way, but I ended up with this for the validation I needed.
<div class="container-fluid">
<div class="row paddings_bottom">
<?php
$hoho = VrfImage::model()->findAll("id_form = $search->id");
$formImage=$this->beginWidget('CActiveForm', array(
'id'=>'verification-form-image',
'action' => Yii::app()->createUrl("backendVerification/default/CreateImage?id=".$modUser->id),
'htmlOptions' => array('enctype' => 'multipart/form-data'),
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>true,
'validateOnType'=>true,
),
));
?>
<div class="col-md-12 col-lg-12">
<table class="table table-bordered" style="margin-bottom: 0;">
<?php
$numQues = [11,22,33,44,55,66,77,88,99,111,222,333];
$nameQues = ['Business license','Company code','Tax register','Export license','Joint venture approved certificate','Land certificate','ISO9001:2008','ISO14001;2004','UL certificate','CE certificate','Quality manual','Quality organization'];
$oo = 0; $ban = 0;
foreach ($numQues as $ii => $NQ){
if($ii==0){
echo '<div class="borTopFormVrf"><span class="White">Company Documentation</span></div>';
}
if($ii <6){
if($oo<2){
if($oo==0){
echo '<tr>';
}
?>
<td class="col-md-6 col-lg-6 nopadd" style="border: 1px solid #000;">
<?php
foreach ($hoho as $key => $value) {
if($hoho[$key]->id_ques == $NQ){
echo '<img src="'.getThemeUri().'/../../VerificationResource/images/'.$hoho[$key]->image.'" style="max-width:100%;">';
$ban = 1;
}
}
if($ban!=1){
echo '<img src="#" style="visibility: hidden;" id="img_prev'.$ii.'" alt="your image"/>';
}
else{ $ban=0; }
?>
<?php echo $form->HiddenField($modImage,"[".$ii."]id_ques",array('value'=>$NQ)); ?>
<div class="col-md-12 col-lg-12" style="border-bottom: solid 1px #000;">
<div class="col-md-7 col-lg-7">
<?php echo $formImage->fileField($modImage,'['.$ii.']image', array( 'onChange'=>'readURL(this,'.$ii.')')); ?>
</div>
<div class="col-md-5 col-lg-5">
<?php
if($ban!=1){
echo '<label id="lbl'.$ii.'" style="visibility: hidden;" onclick="kkk('.$ii.')">X</label>';
}
?>
</div>
</div>
<?php echo $formImage->error($modImage,'['.$ii.']image'); ?>
<div class="text-center">
<?php echo $nameQues[$ii]; ?>
</div>
</td>
<?php if($oo==1){ echo '</tr>'; $oo = -1; }
$oo++;
}}
}
?>
</table>
</div>
<div class="col-md-12 col-lg-12 MT15">
<div class="col-md-2 col-lg-2">
<?php
if(isset($search->id_verifier)){
if($search->id_verifier == userID()){
echo CHtml::submitButton('Save', array('class' => 'btn btn-success btn_formVrf btn_create_address_size GreenVrf'));
}
}
?>
</div>
</div>
<?php $this->endWidget(); ?>
</div>
And later this with function js:
function readURL(input,num) {
if (input.files && input.files[0]) {
if(input.files[0].type=='image/jpeg' || input.files[0].type=='image/gif' || input.files[0].type=='image/png'){
if(input.files[0].size>1000000){
$('#VrfImage_'+num+'_image').val('');
alert("El archivo supera el peso permitido (1MB)");
return false;
}
else{
var reader = new FileReader();
reader.onload = function (e) {
$('#img_prev'+num).css('visibility','visible');
$('#img_prev'+num).attr('src', e.target.result).width(250).height(250);
$('#lbl'+num).css('visibility','visible');
};
reader.readAsDataURL(input.files[0]);
}
}
else{
$('#VrfImage_'+num+'_image').val('');
alert("El archivo no es una imagen valida\n(debe ser JPG, JPEG, GIF o PNG y pesar maximo 1MB.)");
return false;
}
}
}
function kkk(num){
$('#img_prev'+num).css('visibility','hidden');
$('#img_prev'+num).css('height','27px');
$('#VrfImage_'+num+'_image').val('');
$('#lbl'+num).css('visibility','hidden');
}
I have a form for editing a user record. Its updates the record for the first time but when i press the update button again, it shows me an empty screen and it unsets the picture as well. I cannot figure out what I am doign wrong
Below is my code
public function actionEditProfile($affusername = NULL) {
$this->layout = 'layout_home';
if ($this->VarifyUser($affusername) && Yii::app()->user->id) {
$model = new Users('edit'); //apply rules if user comes directly to signup page
// uncomment the following code to enable ajax-based validation
if (isset($_POST['ajax']) && $_POST['ajax'] === 'editprofile-form') {
CActiveForm::validate($model);
Yii::app()->end();
}
if (isset($_POST['Users'])) {
$the_image = CUploadedFile::getInstance($model, 'image');
if (is_object($the_image) && get_class($the_image) === 'CUploadedFile') {
$model->image = $the_image;
}
if (is_object($the_image)) {
$file_name = Yii::app()->user->id . '.' . $model->image->extensionName;
$move = $model->image->saveAs(Yii::getPathOfAlias('webroot') . '/themes/myproject/images/users/' . $file_name);
$_POST['Users']['image'] = $file_name;
}
$model->attributes = $_POST['Users'];
if ($model->validate()) {
// form inputs are valid, do something here
if ($model->updateByPk(Yii::app()->user->id, $_POST['Users'])) {
//$this->setFlashSuccess("Unable to register user, please try again");
$this->setFlashSuccess('Updated successfully, now redirecting.');
//$this->redirect($this->base_url);
} else {
$this->setFlashError("Unable to update user, please try again");
return false;
}
} else {
print_r($model->getErrors());
echo 'validation fail';
exit;
}
}
$user_data = Users::model()->getUsersByUserName($affusername); //getting user information
//print_r($user_data);
//$model=new Users('nonfb-create'); //apply rules if user comes directly to signup page
$this->render('editprofile', array('model' => $model, 'data' => $user_data,));
} else {
$this->redirect($this->base_url);
}
}
My view is
<div class="adminform_wrapp">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'editprofile-form',
'enableAjaxValidation' => false,
'clientOptions' => array(
'validateOnSubmit' => true,
),
'enableClientValidation' => true,
'focus' => array($model, 'first_name'),
'htmlOptions' => array(
'enctype' => 'multipart/form-data'
)
));
echo $form->errorSummary($model);
?>
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_First_Name">First Name: <span class="required">*</span></label>
<?php echo $form->textField($model, 'first_name', array('value' => $data['first_name'])); ?>
<?php $form->error($model, 'first_name'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Last_Name">Last Name: <span class="required">*</span></label>
<?php echo $form->textField($model, 'last_name', array('value' => $data['last_name'])); ?>
<?php $form->error($model, 'last_name'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Email">Email: <span class="required">*</span></label>
<?php echo $form->textField($model, 'email', array('value' => $data['email'])); ?>
<?php $form->error($model, 'email'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Phone_No">Phone No: <span class="required">*</span></label>
<?php echo $form->textField($model, 'phone_no', array('value' => $data['phone_no'])); ?>
<?php $form->error($model, 'phone_no'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label>Username:</label>
<span class="profile-username"><?php echo $data['username']; ?></span> </div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label>Edit Profile picture:</label>
<span class="image-placeholder">
<img src="<?php echo $this->theme_baseurl . '/images/users/' . $data['image']; ?>" style="width:96px; height:96px;"/>
</span>
<div id='file_browse_wrapper'>
<?php
//echo $form->labelEx($model, 'image');
echo $form->fileField($model, 'image', array('id' => 'file_browse'));
echo $form->error($model, 'image');
?>
</div>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<?php echo $form->labelEx($model, 'Address', array('class' => 'fieldname')); ?>
<?php echo $form->textField($model, 'address', array('value' => $data['address'])); ?>
<?php $form->error($model, 'address'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Country">Country: <span class="required">*</span></label>
<select class="error" onchange="print_state('Users_state', this.selectedIndex);" id="Users_country" name ="Users[country]"></select>
<?php $form->error($model, 'country'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_State">State: <span class="required">*</span></label>
<select name ="Users[state]" id ="Users_state"></select>
<script language="javascript">print_state("Users_state", '', "<?php echo $data['state'] ?>");</script>
<?php $form->error($model, 'state'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_City">City: <span class="required">*</span></label>
<?php echo $form->textField($model, 'city', array('value' => $data['city'])); ?>
<?php $form->error($model, 'city'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<label class="fieldname required" for="Users_Zipcode">Zipcode: <span class="required">*</span></label>
<?php echo $form->textField($model, 'zipcode', array('value' => $data['zipcode'])); ?>
<?php $form->error($model, 'zipcode'); ?>
</div>
<!--adminform_row-->
<!--adminform_row-->
<div class="adminform_row">
<input type="submit" class="adminupdate_btn" value="Update">
<input type="reset" class="admincancel_btn" value="Cancel">
</div>
<!--adminform_row-->
<?php $this->endWidget(); ?>
</div>
An empty screen is shown usually when there is a syntactic error.
You can see the error in the apache log (usually at /var/log/apache2/error.log in linux).
As darkheir said, you should see that log file.
It was a syntax error. Also it was updating the complete row in the database where update form was sending only a few fields. I fixed by manually setting the attributes. Below is my code
if (isset($_POST['Users'])) {
//echo "<pre>";
//print_r($model->image);
// print_r($_POST);
// print_r($_FILES);
//echo "</pre>";
$the_image = CUploadedFile::getInstance($model, 'image');
if (is_object($the_image) && get_class($the_image) === 'CUploadedFile') {
$model->image = $the_image;
}
//echo "<pre>";
//print_r($_POST);
//echo "</pre>";
$first_name = $_POST['Users']['first_name'];
$last_name = $_POST['Users']['last_name'];
$email = $_POST['Users']['email'];
$phone_no = $_POST['Users']['phone_no'];
$address = $_POST['Users']['address'];
$country = $_POST['Users']['country'];
$state = $_POST['Users']['state'];
$city = $_POST['Users']['city'];
$zipcode = $_POST['Users']['zipcode'];
if (is_object($the_image)) {
$file_name = Yii::app()->user->id . '.' . $model->image->extensionName;
$model->image->saveAs(Yii::getPathOfAlias('webroot') . '/themes/karmora/images/users/' . $file_name);
$_POST['Users']['image'] = $file_name;
//$model->first_name = $_POST['Users']['first_name'];
$attributes = array(
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email,
'phone_no' => $phone_no,
'image' => $file_name,
'address' => $address,
'country' => $country,
'state' => $state,
'city' => $city,
'zipcode' => $zipcode
);
} else {
$attributes = array(
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email,
'phone_no' => $phone_no,
'address' => $address,
'country' => $country,
'state' => $state,
'city' => $city,
'zipcode' => $zipcode);
}
$model->updateByPk(Yii::app()->user->id, $attributes);
}
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.