Friday, 17 August 2018

Codeigniter : How to get the selected option value in controller



Get the selected option value in controller


Put this code in view:

<select name="color" id="color" class="form_input">
    <option value="Red">Red </option>
    <option value="Green">Green</option>
   <option value="Blue">Blue</option>
   <option value="Yellow">Yellow</option>
   <option value="Pink">Pink</option>
</select>

Now, add following code in controller for get selected value : 

<?php $color= $this->input->post("color"); ?>



Now, get multiple selected option values in contorller


Put this following code in view:

<select  class="default " id="color" name="color[]">
   <option value="">Select color</option>
   <?php foreach ($colors as $color) {  ?>
   <option value="<?php echo $color->color_id;?>">
   <?php echo $color->color_name;?>
   </option>
   <?php } ?>
</select>


Now, add following code in controller or model for get selected values : 

<?php $colors = $this->input->post("color"); ?>










Thursday, 16 August 2018

Codeigniter : Check if id already exists in database

Check if any id already exists in database table and not exist id, insert in table.



$product_category = $this->input->post('product_category');    // product_category is multiple checkbox name


$dataCatBatch = array();
foreach($product_category as $_category){
$ros = $this->db->get_where('product_category',array('product_id'=>$productId,'category_id'=>$_category))->num_rows();
if($ros == 0){
$dataCatBatch[] = array('product_id'=>(int)$productId,'category_id'=>(int)$_category);
}
}

if(count($dataCatBatch) > 0){
$this->db->insert_batch('product_category',$dataCatBatch);
}

Description : product_category is table name. You can change column name according your table column name. 

Jquery : Sum of multiple input fields in one input

Sum of multiple input fields if all input fields have same class in one input field by Jquery

<input type="text" class="pro_qty" value="" />

<input type="text" class="pro_qty" value="" />
<input type="text" class="pro_qty" value="" />
<input type="text" class="pro_qty" value="" />
<input type="text" class="pro_qty" value="" />
<input type="text" class="pro_qty" value="" />
<input type="text" class="total_qty" value="" />
<script>
$(document).on("change", ".pro_qty", function() {
var sum = 0;

$(".pro_qty").each(function(){
sum += +$(this).val();
});

$(".total_qty").val(sum); });
</script>

Friday, 12 May 2017

How to check customer email id is exist or not before registration in Magento?


You can check customer email id is exist or not before registration in Magento by following code.


          $customer = Mage::getModel('customer/customer');
                $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
                $customer->loadByEmail($customer_email);

                if($customer->getId())
                {
                  echo "Customer Exist";
                }