enter image description here
enter image description here
why this happen they are view model controller respectively.
My code is not running but it fetch the data from the database.
How I can resolve this problem please help me.
and thanks in advance.
function getcountry()
{
$this->db->select('*');
$query = $this->db->get('et_country');
return $query->result();
}
function getstate($country_id='')
{
$array = array('status' => 'Active','country_id' => $country_id);
$this->db->select('id,name,country_id');
$this->db->where($array);
$query = $this->db->get('et_state');
return $query->result();
}
function getcity($state_id='')
{
$array = array('status' => 'Active','state_id' => $state_id);
$this->db->select('id,name,state_id');
$this->db->where($array);
$query = $this->db->get('et_city');
return $query->result();
}
public function create_subadmin()
{
$this->load->model('Auction_model');
$data['country'] = $this->Auction_model->getcountry();
$this->load->view('admin/Auction/add_Auction',$data);
}
public function ajax_state_list($country_id)
{
$this->load->model('Auction_model');
$data['state'] = $this->Auction_model->getstate($country_id);
$this->load->view('admin/Auction/add_Auction',$data);
}
public function ajax_city_list($state_id)
{
$this->load->model('Auction_model');
$data['city'] = $this->Auction_model->getcity($state_id);
$this->load->view('admin/Auction/add_Auction',$data);
}
<script>
function getstatedetails(id)
{
//alert('this id value :'+id);
$.ajax({
type: "POST",
url: '<?php echo site_url('admin/Auction_controller/ajax_state_list').'/';?>'+id,
data: id='cat_id',
success: function(data){
// alert(data);
$('#old_state').html(data);
},
});
}
</script>
<script>
function getcitydetails(id)
{
$.ajax({
type: "POST",
url: '<?php echo site_url('admin/Auction_controller/ajax_city_list').'/';?>'+id,
data: id='st_id',
success: function(data){
$('#old_city').html(data);
},
});
}
</script>
<div class="form-group">
<label>Country</label><br>
<select name="country_id" class="form-control" id="country_details" onChange="getstatedetails(this.value)">
<option value="<?php echo $rs->name ?>" selected="selected" >Select</option>
<?php
foreach ($country_id as $rs) {
?>
<option value="<?php echo $rs->id; ?>"><?php echo $rs->name ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>State</label><br>
<select name="state_id" class="form-control" id="old_state" onChange="getstatedetails(this.value)">
<option value="<?php echo $rs->name ?>" selected="selected" >Select</option>
<?php
foreach ($state_id as $rs) {
?>
<option value="<?php echo $rs->id; ?>"><?php echo $rs->name ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>City</label><br>
<select name="city_id" class="form-control" id="old_city" onChange="getcitydetails(this.value)">
<option value="" selected="selected" >Select</option>
<?php
foreach ($city_id as $rs) {
?>
<option value="<?php echo $rs->id; ?>"><?php echo $rs->name ?></option>
<?php } ?>
</select>
</div>
Try to change the ajax call like this :
var values = {
'cat_id': id
};
$.ajax({
url: "<?php echo site_url('admin/Auction_controller/ajax_state_list').'/';?>"+id,
type: "post",
data: values,
success: function(data) {
$('#old_state').html(data);
}
});
Related
I have trying to post some values to table with an image but when i try to upload file name saved in table but image doesn't move to directory. i have checked directory permission.
but still no luck.
function:
function add_multiple_choice_question($quiz_id) {
if (sizeof($this->input->post('options')) != $this->input->post('number_of_options')) {
return false;
}
foreach ($this->input->post('options') as $option) {
if ($option == "") {
return false;
}
}
if (sizeof($this->input->post('correct_answers')) == 0) {
$correct_answers = [""];
} else {
$correct_answers = $this->input->post('correct_answers');
}
$data['quiz_id'] = $quiz_id;
$data['title'] = html_escape($this->input->post('title'));
$data['number_of_options'] = html_escape($this->input->post('number_of_options'));
$data['type'] = 'multiple_choice';
$data['options'] = json_encode($this->input->post('options'));
$data['correct_answers'] = json_encode($correct_answers);
if (!file_exists('uploads/quiz_image')) {
mkdir('uploads/quiz_image', 0777, true);
}
if ($_FILES['quiz_image']['name'] == "") {
$data['quiz_image'] = 'category-thumbnail.png';
} else {
$data['quiz_image'] = md5(rand(10000000, 20000000)) . '.jpg';
move_uploaded_file($_FILES['quiz_image']['tmp_name'], 'uploads/quiz_image/' . $data['quiz_image']);
}
$this->db->insert('question', $data);
return true; }
Unable to move file to directory
Form
<form action="<?php echo site_url('admin/quiz_questions/'.$param2.'/add'); ?>" enctype="multipart/form-data" method="post" id = 'mcq_form'>
<input type="hidden" name="question_type" value="mcq">
<div class="form-group">
<label for="title"><?php echo get_phrase('question_title'); ?></label>
<input class="form-control" type="text" name="title" id="title" required>
</div>
<div class="form-group">
<label for="title"><?php echo get_phrase('quiz_image'); ?></label>
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input" name="quiz_image" onchange="changeTitleOfImageUploader(this)" accept="image/*">
<label class="custom-file-label ellipsis" for=""><?php echo get_phrase('choose_file'); ?></label>
</div>
</div>
</div>
<div class="form-group" id='multiple_choice_question'>
<label for="number_of_options"><?php echo get_phrase('number_of_options'); ?></label>
<div class="input-group">
<input type="number" class="form-control" name="number_of_options" id="number_of_options" data-validate="required" data-message-required="Value Required" min="0">
<div class="input-group-append" style="padding: 0px"><button type="button" class="btn btn-secondary btn-sm pull-right" name="button" onclick="showOptions(jQuery('#number_of_options').val())" style="border-radius: 0px;"><i class="fa fa-check"></i></button></div>
</div>
</div>
<div class="text-center">
<button class = "btn btn-success" id = "submitButton" type="button" name="button" data-dismiss="modal"><?php echo get_phrase('submit'); ?></button>
</div>
application is using script but i am not experienced with it.
<script type="text/javascript">
function showOptions(number_of_options){
$.ajax({
type: "POST",
url: "<?php echo site_url('admin/manage_multiple_choices_options'); ?>",
data: {number_of_options : number_of_options},
success: function(response){
jQuery('.options').remove();
jQuery('#multiple_choice_question').after(response);
}
});
}
$('#submitButton').click( function(event) {
$.ajax({
url: '<?php echo site_url('admin/quiz_questions/'.$param2.'/add'); ?>',
type: 'post',
data: $('form#mcq_form').serialize(),
success: function(response) {
if (response == 1) {
success_notify('<?php echo get_phrase('question_has_been_added'); ?>');
}else {
error_notify('<?php echo get_phrase('no_options_can_be_blank_and_there_has_to_be_atleast_one_answer'); ?>');
}
}
});
showLargeModal('<?php echo site_url('modal/popup/quiz_questions/'.$param2); ?>', '<?php echo get_phrase('manage_quiz_questions'); ?>');
});
</script>
Controller
public function quiz_questions($quiz_id = "", $action = "", $question_id = "") {
if ($this->session->userdata('admin_login') != true) {
redirect(site_url('login'), 'refresh');
}
$quiz_details = $this->crud_model->get_lessons('lesson', $quiz_id)->row_array();
if ($action == 'add') {
$response = $this->crud_model->add_quiz_questions($quiz_id);
echo $response;
}
elseif ($action == 'edit') {
$response = $this->crud_model->update_quiz_questions($question_id);
echo $response;
}
elseif ($action == 'delete') {
$response = $this->crud_model->delete_quiz_question($question_id);
$this->session->set_flashdata('flash_message', get_phrase('question_has_been_deleted'));
redirect(site_url('admin/course_form/course_edit/'.$quiz_details['course_id']));
}
}
i searched too much n tried all trick but no luck.
I am new to Codeigniter and created a project in which dropdown grab the data from table 1 and I want to save the data to table 2. However, the other value option is saving but not dropdown values. Code is given below.
Model:
function getPriviousScore() {
$this->db->select('*');
$this->db->from('ielts_previous_score');
$query = $this->db->get();
return $query->result_array();
}
Controller:
$data['ielts_previous_score'] = $this->enquiry_model->getPriviousScore();
View:
<select name="ielts_previous_score" class="form-control">
<option value=""><?php echo $this->lang->line('select'); ?></option>
<?php foreach ($ielts_previous_score as $key => $value) { ?>
<option value="<?php print_r($value['ielts_previous_score']); ?>" <?php if (set_value('ielts_previous_score') == $value['ielts_previous_score']) { ?>selected=""<?php } ?>><?php print_r($value['ielts_previous_score']); ?></option>
<?php } ?>
</select>
MODEL
function getPriviousScore() {
$this->db->select('*');
$this->db->from('ielts_previous_score');
$query = $this->db->get();
return $query->result_array();
}
CONTROLLER
$data['ielts_previous_score'] = $this->enquiry_model->getPriviousScore();
VIEW
<select name="ielts_previous_score" class="form-control">
<option value=""><?php echo $this->lang->line('select'); ?></option>
<?php foreach ($ielts_previous_score as $key => $value) { ?>
<option value="<?php echo $value['ielts_previous_score']; ?>" <?php if
(set_value('ielts_previous_score') == $value['ielts_previous_score']) { ?
>selected=""<?php } ?>><?php echo $value['ielts_previous_score']; ?></option>
<?php } ?>
</select>
please help me i would like to delete some check box if checkbox unchecked.
My checkbox is automatic show from database my sql. and i would like to delete some checkbox when checkbox in not checked.
PLease Help
its my controller
public function edit_overview($id_product)
{
if ($this->input->post('submit')) {
foreach ($id_overview = $this->input->post('id_overview') as $rm) {
$check_idoverview = $this->Biostar->check_idoverview($id_product, $rm);
if ($check_idoverview==unchecked){
$data['file'] = $check_idoverview;
$this->Biostar->delete_overview($check_idoverview,$id_product);
}else{
if ($check_idoverview > 0) {
} else {
$datafield = array(
'id_product' => $id_product,
'id_overview' => $rm
);
$this->Biostar->saveoverviewproduct($datafield);
$message_success = "Data Has Been Update";
}
}
}
}
$data['message_success'] = #$message_success;
$field = $this->Biostar->get_overview($id_product);
$fieldid_product = $this->Biostar->get_id_product($id_product);
$data['field'] = $field;
$data['id_product'] = $fieldid_product;
$data['content'] = "biostar/edit_overview_product";
$this->load->view('dashboard/index', $data);
}
My Model
function delete_overview($check_overview,$id_product)
{
$sql = "delete from overview_briostar where id_overview='$check_overview' AND id_product='$id_product'";
return $sql;
}
My View
<form method="post" action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $id_product->id_product; ?>">
<div class="box-body">
<?php foreach ($speed as $row){ ?>
<div class="checkbox">
<label>
<input type="checkbox" name="id_overview[]" onClick="EnableSubmit3(this)" value="<?php echo $row['id_overview']; ?>"<?php foreach ($field as $wor){ ?> <?php if($row['id_overview']==$wor['id_overview']) echo "checked";?> <?php } ?> ><?php echo $row['title']; ?>
</label>
</div>
<?php } ?>
<!-- /input-group -->
</div>
<div class="box-footer">
<input value="Submit" type="submit" id="submit3" name="submit" class="btn btn-primary">
</div>
</form>
Unchecked checkbox value will not get posted, so you have to use jquery and ajax
Your checkbox
<input class="id_overview" type="checkbox" name="id_overview[]" value="<?php echo $row['id_overview']; ?>"<?php foreach ($field as $wor){ ?> <?php if($row['id_overview']==$wor['id_overview']) echo "checked";?> <?php } ?> ><?php echo $row['title']; ?>
your jquery
<script type="text/javascript">
$(document).ready(function() {
$("form#frm").submit(function(e) { // give a id to your form
e.preventDefault();
var ids = new Array();
$('.id_overview').each(function() {
if ($(this).is(':checked')) {
} else {
ids.push($(this).val());
}
});
$.ajax({
// send ids through your ajax code
});
});
});
</script>
create a new function and call it by ajax to delete the ids.
You can try like this
<form method="post" action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $id_product->id_product; ?>">
<div class="box-body">
<?php foreach ($speed as $row){ ?>
<div class="checkbox">
<label>
<input type="hidden" name="all_id[]" value="<?php echo $row['id_overview']; ?>" />
<input type="checkbox" name="id_overview<?php echo $row['id_overview']; ?>" onClick="EnableSubmit3(this)" value="<?php echo $row['id_overview']; ?>"<?php foreach ($field as $wor){ ?> <?php if($row['id_overview']==$wor['id_overview']) echo "checked";?> <?php } ?> ><?php echo $row['title']; ?>
</label>
</div>
<?php } ?>
<!-- /input-group -->
</div>
<div class="box-footer">
<input value="Submit" type="submit" id="submit3" name="submit" class="btn btn-primary">
</div>
</form>
and in you controller
if ($this->input->post('submit')) {
foreach($all_id as $row_id)
{
if($this->input->post('id_overview'.$row_id))
{
//do action where id is present
}
else
{
//do action if unchecked by getting id $row_id
}
}
}
I want to include Categories and all their subcategories using chained select in Advanced search. Chained select is only a suggestion.
If any other method is there to load the categories along with sub categories in another drop down means, Those methods are also welcome.
I have achieved the above using Ajax in magento.
app/design/frontend/base/default/template/catalogsearch/advanced/form.phtml
<li>
<label for="section_search_field">Select Vehicle</label><br>
<select name="category" id="vehicle">
<option selected="selected">--Select Vehicle--</option>
<?php
$sql=mysql_query("select name,entity_id from catalog_category_flat_store_1 where parent_id=8");
while($row=mysql_fetch_array($sql))
{
$id=$row['entity_id'];
$data=$row['name'];
echo '<option value="'.$id.'">'.$data.'</option>';
} ?>
</select>
</li>
<li>
<label for="category_search_field">Select Manufacturere</label><br>
<select name="category" id="manufacturere" class="manufacturere" >
<option value="">--Choose Manufacturere--</option>
</select>
</li>
<li>
<label for="subcategory_search_field">Select Type</label><br>
<select name="sub" id="vehicle_type" class="vehicle_type">
<option value="">--Choose type--</option>
</select>
</li>
<li>
<label for="category_search_field">Select Model</label><br>
<select name="category" id="vehicle_model" class="vehicle_model">
<option value="">--Choose Model--</option>
</select></li>
<?php foreach ($this->getSearchableAttributes() as $_attribute): ?>
<?php $_code = $_attribute->getAttributeCode() ?>
<li>
<label for="<?php echo $_code ?>"><?php echo $this->getAttributeLabel($_attribute) ?></label>
<?php switch($this->getAttributeInputType($_attribute)):
case 'number': ?>
<div class="input-range">
<input type="text" name="<?php echo $_code ?>[from]" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>" class="input-text validate-number" maxlength="<?php echo $maxQueryLength;?>" />
<span class="separator">-</span>
<input type="text" name="<?php echo $_code ?>[to]" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>" class="input-text validate-number" maxlength="<?php echo $maxQueryLength;?>" />
</div>
<?php break;
case 'price': ?>
<div class="input-range">
<input name="<?php echo $_code ?>[from]" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>" class="input-text validate-number" type="text" maxlength="<?php echo $maxQueryLength;?>" />
<span class="separator">-</span>
<input name="<?php echo $_code ?>[to]" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>" class="input-text validate-number" type="text" maxlength="<?php echo $maxQueryLength;?>" />
<small>(<?php echo $this->getCurrency($_attribute); ?>)</small>
</div>
<?php break;
case 'select': ?>
<div class="input-box">
<?php echo $this->getAttributeSelectElement($_attribute) ?>
</div>
<?php break;
case 'yesno': ?>
<?php echo $this->getAttributeYesNoElement($_attribute) ?>
<?php break;
case 'date': ?>
<div class="input-range">
<?php echo $this->getDateInput($_attribute, 'from') ?>
<span class="separator">-</span>
<?php echo $this->getDateInput($_attribute, 'to') ?>
</div>
<?php break;
default: ?>
<div class="input-box">
<input type="text" name="<?php echo $_code ?>" id="<?php echo $_code ?>" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute)) ?>" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>" class="input-text <?php echo $this->getAttributeValidationClass($_attribute) ?>" maxlength="<?php echo $maxQueryLength;?>" />
</div>
<?php endswitch; ?>
</li>
<?php endforeach; ?>
</ul>
In the same file Within script tag I used ajax call as follows:
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function($) {
$j('#vehicle').change(function()
{
var optionCheckVechile = $j('select#vehicle option:selected').text();
var optionCheckManufacturer = $j('select#manufacturere option:selected').text();
var optionCheckType = $j('select#vehicle_type option:selected').text();
var optionCheckModel = $j('select#vehicle_model option:selected').text();
if(optionCheckType != '--Select type--'){
$('select#vehicle_type option:eq(0)').attr("selected", true);
}
if(optionCheckModel != '--Select Model--'){
$('select#vehicle_model option:eq(0)').attr("selected", true);
}
if((optionCheckVechile == 'Car')|| (optionCheckVechile == 'Bus')){
$j("#vehicle_type").prop('disabled',false);
$j('#vehicle_type').css('background-color','#fff');
$j("#vehicle_model").prop('disabled',false);
$j('#vehicle_model').css('background-color','#fff');
}
else if((optionCheckVechile == 'Bike') || (optionCheckVechile == 'Truck')|| (optionCheckVechile == 'Auto')){
$j("#vehicle_model").prop('disabled',true);
$j('#vehicle_model').css('background-color','#ccc');
}
else{
$j("#vehicle_type").prop('disabled',true);
$j('#vehicle_type').css('background-color','#ccc');
$j("#vehicle_model").prop('disabled',true);
$j('#vehicle_model').css('background-color','#ccc');
}
var id=$j(this).val();
var dataString = 'id='+ id;
$j.ajax
({
type: "POST",
url: "<?php echo $this->getUrl('catalogsearch/ajax/vehicle') ?>",
data: dataString,
cache: false,
success: function(html)
{
$j("#manufacturere").html(html);
}
});
$j("#manufacturer").load();
$j("#vehicle_model").load();
$j("#vehicle_type").load();
});
$j('#manufacturere').change(function()
{
var optionCheckModel = $j('select#vehicle_model option:selected').text();
if(optionCheckModel != '--Select Model--'){
$('select#vehicle_model option:eq(0)').attr("selected", true);
}
var id=$j(this).val();
var dataString = 'id='+ id;
$j.ajax
({
type: "POST",
url: "<?php echo $this->getUrl('catalogsearch/ajax/manufacturer') ?>",
data: dataString,
cache: false,
success: function(html)
{
$j("#vehicle_type").html(html);
}
});
});
$j('#vehicle_type').change(function()
{
var id=$j(this).val();
var dataString = 'id='+ id;
$j.ajax
({
type: "POST",
url: "<?php echo $this->getUrl('catalogsearch/ajax/type') ?>",
data: dataString,
cache: false,
success: function(html)
{
$j("#vehicle_model").html(html);
}
});
});
});
Next in app/code/core/Mage/CatalogSearch/controllers/AjaxController.php add the following code.
class Mage_CatalogSearch_AjaxController extends Mage_Core_Controller_Front_Action
{
public function vehicleAction()
{
$id=$_POST['id'];
$sql=mysql_query("select name,entity_id from catalog_category_flat_store_1 where parent_id='$id'");
echo '<option value=0>--Select Manufacturere--</option>';
while($row=mysql_fetch_array($sql))
{
$id=$row['entity_id'];
$data=$row['name'];
echo '<option value="'.$id.'">'.$data.'</option>';
}
}
public function manufacturerAction()
{
$id=$_POST['id'];
$sql=mysql_query("select name,entity_id from catalog_category_flat_store_1 where parent_id='$id'");
echo '<option value=0>--Select type--</option>';
while($row=mysql_fetch_array($sql))
{
$id=$row['entity_id'];
$data=$row['name'];
echo $id;
echo '<option value="'.$id.'">'.$data.'</option>';
}
}
public function typeAction()
{
$id=$_POST['id'];
$sql=mysql_query("select name,entity_id from catalog_category_flat_store_1 where parent_id='$id'");
echo '<option value=0>--Select Model--</option>';
while($row=mysql_fetch_array($sql))
{
$id=$row['entity_id'];
$data=$row['name'];
echo $id;
echo '<option value="'.$id.'">'.$data.'</option>';
}
}
}
Then refresh the page and run advanced search. Chained select will work for the categories loaded according to the parent ID.
Note: This is only for loading a particular category and their sub category.
I am sending dynamically created form fields to CodeIgniter via ajax.
<div class="form-element">
<input type="radio" id="delete-radio[1]" name="delete-radio[1]" value="1">
</div>
<div class="form-element">
<label for="member_id[1]">Membership ID</label>
<input type="text" id="member_id[1]" name="member_id[]" autocomplete="off" value="<?php echo set_value('member_id[1]'); ?>"/>
<?php echo form_error('member_id[1]', '<div class="error">', '</div>'); ?>
</div>
<div class="form-element">
<label for="member_name[1]">Name</label>
<input type="text" id="member_name[1]" name="member_name[]" autocomplete="off" value="<?php echo set_value('member_name[1]'); ?>"/>
<?php echo form_error('member_name[1]', '<div class="error">', '</div>'); ?>
</div>
<div class="form-element">
<label for="member_address[1]">Address</label>
<input type="text" id="member_address[1]" name="member_address[]" autocomplete="off" value="<?php echo set_value('member_address[1]'); ?>"/>
<?php echo form_error('member_address[1]', '<div class="error">', '</div>'); ?>
</div>
I use the following to send them to their controller:
$('#submit').click(function() {
var form_data = $('#ajax-form').serialize();
alert(form_data);
$.ajax({
url: "<?php echo site_url('ajax_ci/ajax_check'); ?>",
type: 'POST',
async : false,
data: form_data,
success: function(msg) {
$('#form-name').append(msg);
}
});
return false;
});
Here is the controller:
if ($this->input->is_ajax_request()) {
$this->form_validation->set_rules('member_id[]', 'member ID', 'trim|required|xss_clean');
$this->form_validation->set_rules('member_name[]', 'member name', 'trim|required|xss_clean');
$this->form_validation->set_rules('member_address[]', 'member password', 'trim|required|xss_clean');
if($this->form_validation->run() == FALSE) {
echo validation_errors();
} else {
// connect to database
}
} else {
echo "Work on it! Don't give up!";
}
The screenshot below is currently what happens.
But I want these errors to appear in their respective individual form_errors
Is this possible in my current setup?
In the validation errors that you return from the server, you will need to include information about which field failed. Probably an array of (fieldname=>errormsg). Your ajax response handler can then find the correct field and append the message to the DOM accordingly.