December 26, 2015

AngularJs how to sum two dynamic value from text box?



- Please write following function in script file for sum two dynamic value from text box,

angular.module('App').filter('twosum', function() {
  return function(items) {
    var sum = 0;
    items.forEach(function(item) {
      if (item.item_count) {
         sum += item.item_count;    
      }
    })
    return sum;
  }
})

- In HTML/PHP file where you want to display above sum value write below short code,

<span>{{ table.fields | twosum }}</span>

Enjoy!

December 23, 2015

PHP - When submit form string replace space to Â



Today I working on a PHP project and I face one spacing problem like when I submit form with CKeditor then all space &nbsp; replace with  undefined character,

So I find a best solution for that and share it here.

Fist please include following meta line in <head> tag:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

And second thing is when you submit CKeditor field then used 'utf8_decode' function, see in below example:

$message=utf8_decode($_REQUEST['message']);

Here 'message' is your field name.

Enjoy!

December 21, 2015

How to disable click in AngularJS?




Here is a simple example for disable click in AngularJS,

<body ng-app="ngToggle">
    <div ng-controller="AppCtrl">
        <button ng-click="disableClick(1)">Disable ng-click</button>
    </div>
</body>

In JS:

angular.module('ngToggle', [])
    .controller('AppCtrl',['$scope', function($scope){
    $scope.flag = 0;
    $scope.disableClick = function(n) {
        if (n && n !== $scope.flag) {
            $scope.flag = n;
            alert("Clicked!");
        }
        return false;
    }
}]);




DEMO


Enjoy!

December 15, 2015

PHP - SQL select query return array with used ID field as a key


                                               



In SQL select query while loop you can used ID fields as array key, it's simple. Here is example for that:

<?php
$selRes=mysql_query("SELECT id, name FROM TableName order by id DESC";
if(mysql_affected_rows()>0)
{
$data=array();
while($rowSale=mysql_fetch_array($selRes))
{
    $data[$row[0]] = $rowSale[1];
}
}

//Output
print_r($data);
array([1]=>'name1',[2]=>'name2',[3]=>'name3');

?>

Enjoy!

December 13, 2015

Magento - How to add static page link to main menu?

- Hello friends finally I find the solution for add static page link to main menu in magento CMS,

- First find the top.phtml file from this page: app/design/frontend/default/YourThemeName/template/catalog/navigation/top.phtml

- Before do any changes on this file please take copy of orignal top.phtml file,

- Below is default code of top.phtml file:


<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
    <ul id="nav">
       <?php echo $_menu ?>
    </ul>
</div>
<?php endif ?>

- You shoud modified as per below example where I add Home link:

<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
    <ul id="nav">
     <li><a href="/">Home</a><li>
     <?php echo $_menu ?>
    </ul>
</div>
<?php endif ?>

- Or you should also add and magento block shord code (In block you define static menu link in <ul><li> format):

<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
    <ul id="nav">
     <li><a href="/">Home</a><li>
     <?php echo $_menu ?>
     <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('navbar_links')->toHtml() ?>  
   </ul>
</div>
<?php endif ?>

- In above example 'navbar_links' is block identifier name.


Enjoy!

December 11, 2015

Ajax concat FormData form + parameters


For Ajax FormData add extra parameters to pass data in PHP file,

See below example for that,

var fd = new FormData(document.getElementById("form"));
fd.append("CustomField", "This is some extra data");
$.ajax({
  url: "stash.php",
  type: "POST",
  data: fd,
  processData: false,  // tell jQuery not to process the data
  contentType: false   // tell jQuery not to set contentType
});

Enjoy!

Multiple ckeditor used on one page with AngularJS.



Yes, its possible to used multiple ckeditor on one page with AngularJs, please see below example OR see here

app.directive('ckEditor', [function () {
    return {
        require: '?ngModel',
        link: function ($scope, elm, attr, ngModel) {

            var ck = CKEDITOR.replace(elm[0]);

            ck.on('pasteState', function () {
                $scope.$apply(function () {
                    ngModel.$setViewValue(ck.getData());
                });
            });

            ngModel.$render = function (value) {
                ck.setData(ngModel.$modelValue);
            };
        }
    };
}])

Enjoy!

Integrating Google reCAPTCHA v3 in HTML Form with PHP

  What is Google reCAPTCHA v3? Google reCAPTCHA is a free service that helps protect websites from spam and abuse. reCAPTCHA v3 is the lates...