Saturday 29 December 2018

How to set default image on image loaded broken?



<!DOCTYPE html>
<html class="" lang="en-US">
<head>
<meta charset="UTF-8" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.min.js"></script>
<!-- or -->
<!-- <script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.js"></script> -->
<style type="text/css">.image-thumb {display: inline-block;margin: 10px;}</style>
</head>
<body>
<div id="product_div">
<div class="image-thumb"><img src="image/product_01.jpg" class="thumbnail-img" width="100" height="100"></div>
<div class="image-thumb"><img src="image/product_02.jpg" class="thumbnail-img" width="100" height="100"></div>
<div class="image-thumb"><img src="image/product_03.jpg" class="thumbnail-img" width="100" height="100"></div>
<div class="image-thumb"><img src="image/product_04.jpg" class="thumbnail-img" width="100" height="100"></div>
<div class="image-thumb"><img src="image/product_05.jpg" class="thumbnail-img" width="100" height="100"></div>
<div class="image-thumb"><img src="image/image/product_06.jpg" class="thumbnail-img" width="100" height="100"></div>
<div class="image-thumb"><img src="image/image/product_07.jpg" class="thumbnail-img" width="100" height="100"></div>
</div>

<script type="text/javascript">
jQuery(document).ready(function(){
if (jQuery('#product_div').length) {
jQuery('#product_div').imagesLoaded().always( function( instance ) {
console.log('all images loaded');
}).done( function( instance ) {
console.log('all images successfully loaded');
}).fail( function(instance2) {
console.log('all images loaded, at least one is broken');
}).progress( function( instance, image ) {
var result = image.isLoaded ? 'loaded' : 'broken';
console.log( 'image is => ' + result + ' for ' + image.img.src );
if(result == 'broken'){
var default_images = ["default_01.jpg","default_02.jpg","default_03.jpg","default_04.jpg","default_05.jpg"];
var new_image_name = default_images[Math.floor(Math.random()*default_images.length)];
console.log("default image is" + new_image_name); /* Random image select */
var default_img = 'default_images/' + new_image_name;
image.img.src = default_img;
}
});
}
});
</script>
</body>
</html>

Thursday 6 December 2018

Export Database From MySQL






# Open CMD
# Step1: Change the directory folder current directory to mysql bin directory.
C:\Users\PHPKishan> cd D:\wamp64\bin\mysql\mysql5.7.19\bin ↲

# Step2: write below command line and in this cmd
D:\wamp64\bin\mysql\mysql5.7.19\bin>mysqldump --databases --user=[Username] --password [DBNAME] > [DIR PATH]\[DBNAME.sql] ↲

 EX D:\wamp64\bin\mysql\mysql5.7.19\bin>mysqldump --databases --user=root --password test_table > DB\test_table_bk.sql ↲

# Step3: Enter password
Enter password:***** ↲

# Step4: See exported database in you directory

Friday 2 November 2018

reCAPTCHA V3 Example in PHP


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
## reCAPTCHA V3 key define ##
#client-side
define('RECAPTCHA_SITE_KEY', 'reCAPTCHA_site_key'); // define here reCAPTCHA_site_key
#server-side
define('RECAPTCHA_SECRET_KEY', 'reCAPTCHA_secret_key'); // define here reCAPTCHA_secret_key

class Captcha {
public function getCaptcha($SecretKey) {
$data = array(
'secret' => RECAPTCHA_SECRET_KEY,
'response' => $SecretKey
);
$verify = curl_init();
curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($verify, CURLOPT_POST, true);
curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
$response_data = curl_exec($verify);
$response_data = json_decode($response_data);
curl_close($verify);
//echo "<pre>"; print_r($response_data); echo "</pre>";
return $response_data;
}
}

///////////////////////////// OR /////////////////////////////
/*
class Captcha {
public function getCaptcha($SecretKey) {
$Resposta = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . RECAPTCHA_SECRET_KEY . "&response={$SecretKey}");
$Retorno = json_decode($Resposta);
return $Retorno;
}
}
*/

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//echo "<pre>"; print_r($_REQUEST); echo "</pre>";
$ObjCaptcha = new Captcha();
$Retorno = $ObjCaptcha->getCaptcha($_POST['g-recaptcha-response']);
//echo "<pre>"; print_r($Retorno); echo "</pre>";
if ($Retorno->success) {
echo '<p style="color: #0a860a;">CAPTCHA was completed successfully!</p>';
} else {
$error_codes = 'error-codes';
if (isset($Retorno->$error_codes) && in_array("timeout-or-duplicate", $Retorno->$error_codes)) {
$captcha_msg = "The verification expired due to timeout, please try again.";
} else {
$captcha_msg = "Check to make sure your keys match the registered domain and are in the correct locations.<br> You may also want to doublecheck your code for typos or syntax errors.";
}
echo '<p style="color: #f80808;">reCAPTCHA error: ' . $captcha_msg . '</p>';
}
}
?>

<div class="contact_form">
<div class="" style="margin-top:0px;margin-bottom:15px;">
<div class="" style="width:50%">
<form id="Form1" name="Form1" action="" method="POST">
<label for="fname">First Name*</label><br>
<input type="text" name="fname" id="fname" required autofocus><br><br>

<label for="lname">Last Name*</label><br>
<input type="text" name="lname" id="lname" required><br><br>

<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"><br>
<input type="submit">
</form>
</div>
</div>
</div>

<script src="https://www.google.com/recaptcha/api.js?render=<?php echo RECAPTCHA_SITE_KEY; ?>"></script>
<script>
grecaptcha.ready(function () {
grecaptcha.execute('<?php echo RECAPTCHA_SITE_KEY; ?>', {action: 'homepage'}).then(function (token) {
document.getElementById('g-recaptcha-response').value = token;
});
});
</script>
</body>
</html>

Thursday 1 November 2018

Multiple words of string replace with str_replace in PHP

<?php
    ## Converting utf8 characters to iso-88591 manually in PHP
    echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />";   
    function str_replace_char(){ 
        $find = array('“', '’', '…', 'â€"', 'â€"', '‘', 'é', 'Â', '•', 'Ëœ', 'â€'); // en dash
        $replace = array('"', '’', '…', '—', '–', '‘', 'é', '', '•', '˜', '"'); // original
        $new_str_content = str_replace( $find,$replace,$str_content);
        return $new_str_content;
    }
   
    $string = "It’s Getting the Best of Me";
    echo $new_string = str_replace_char($string);
?>

Tuesday 2 October 2018

How to prevent multiple clicks on submit button in jQuery?

<script type="text/javascript">
    function ValidationEvent() {
      if (name != '' && email != '' && contact != ''){
          return true;
       }
       return false;
    }

    var Validation_result = false;

    jQuery("#enquiry_form").submit(function(e){
       if (jQuery('#enquiry_submit_btn').data('dont') == 1)return;
   
       // submit button disabled for click
       jQuery('#enquiry_submit_btn').data('dont', 1);
      
       // Validation
       Validation_result = ValidationEvent();
      
       if(Validation_result == false){
        // submit button enable for click
        jQuery('#enquiry_submit_btn').data('dont', 0); 
       }
    });

    jQuery('#enquiry_reset_btn').click(function(){
       jQuery('#enquiry_form')[0].reset();
       // submit button enable for click
       jQuery('#enquiry_submit_btn').data('dont', 0); 
    });
</script>

Wednesday 20 June 2018

Why type="file" does not Work with Safari Browser? in Contact Form 7


Note: Script Must be written in header

<script>
jQuery(function() {
var input_file = [];
jQuery('form.wpcf7-form').on('submit', function() {
console.log("-------------------------------");
var i = 0;
jQuery('input[type=file]').each(function() {
if (jQuery(this).val() === '') {
jQuery(this).attr('type', 'hidden');
input_file[i++] = jQuery(this).attr('name');
}
});
console.log("Type Change File To Hidden: "+input_file);
});

jQuery( document ).ajaxComplete(function() {
//AJAX RESPONSES
console.log("Array in File item: "+input_file.length);
if(input_file.length > 0){
jQuery.each(input_file, function(key, index){
console.log("Type Change Hidden To File: "+key +'=> '+index);
jQuery('input[name='+input_file[key]+']').attr('type', 'file');
});
input_file = [];
}
console.log("Response: " + jQuery(".wpcf7-response-output").html());
});
});
</script>

Please try this and give your review.

Monday 18 June 2018

Detect Safari Browser Using jQuery

<script>
if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1)  {
alert('Now, You are using safari browser...');  
}else{
alert('Now, You are not using safari browser...');
}
</script>


Saturday 16 June 2018

How to Disable Date on Month Change in Datepicker Using jQuery?

I have created disable dates on change month in jQuery UI Datepicker. The Datepicker shows the disable date in Datepicker.

While click on Next or Prev month one Ajax page call for get disable date list.

In this demo, I have set a random date to disable. But you can set disable dates list in JSON format as per your requirement.

This demo will take little time for disabling date in Datepicker. Because of every change month in call callAJAX only for this month.



Download this Scrip Code of Disable Datepicker Click Here

Saturday 9 June 2018

How to temporarily disable a button click in jQuery?

<script>
$("#button_id").click(function() {
  if($(this).data('dont')==1) return;
  $(this).data('dont',1);

  // Do Process .....

  $(this).data('dont',0);
}

///////// OR /////////

$("#button_id").click(function() {
  if($("#button_id").data('dont')==1) return;
  $("#button_id").data('dont',1);

  // Do Process .....

  $("#button_id").data('dont',0);
}
// Note: Remeber that $.data() would work only for items with ID.
</script>

Wednesday 25 April 2018

How to get Last Month's record data from MySQL Database?



SELECT * from product_order WHERE YEAR(order_date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH) and MONTH(order_date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)



Tuesday 24 April 2018

How to get This Month's record data from MySQL Database?


SELECT * from product_order WHERE MONTH(order_date) = MONTH(NOW()) and YEAR(order_date) = YEAR(NOW())


Saturday 21 April 2018

Monday 16 April 2018

How To Create Shortcode In WordPress with parameters?



<?php
### the shortcode code add in theme’s functions.php file  ###
// "do_shortcode" but without the wrapping <p> of Shortcodes
function do_shortcode_boc($content) {
 $array = array (
        '<p>[' => '[',
        ']</p>' => ']',
        ']<br />' => ']'
    );
$content = strtr($content, $array);
$content = do_shortcode($content);
    return $content;
}

function shortcode_shortcodename($atts, $content = null) {   
$atts = shortcode_atts(
array(
'title' => '',
'image' => '',
        ), $atts);

$title = $atts['title'] ? $atts['title'] : '';
$image = $atts['image'] ? $atts['image'] : '';

$str = '<li>
<div class="icon_item">
<img src="'.$image.'">
<p>'.html_entity_decode($title).'</p>
<div class="icon_overlay">
<p>'.do_shortcode($content).'</p>
</div>
</div>
</li>';
return $str;
}
add_shortcode('shortcodename', 'shortcode_shortcodename');

?>

##### Using below code to display shortcode detail  #####

[shortcodename title="my title" image="example.jpg"]
<div>
<p> Shortcode content </p>
</div>
[/shortcodename]

##### OR #####

<?php
echo do_shortcode('[shortcodename]');
?>

Saturday 3 February 2018

Set only first letter capital other in lowercase in PHP SQL

$sql = "SELECT concat(left(emp_name,1),substring(lower(emp_name),2)) as emp_name FROM employee";

Input    : "Raj Kumar"
Output : "Raj kumar"

Friday 5 January 2018

WAMP: Missing http://localhost/ in urls , wrong WAMP projects url

1. Open wamp/www/index.php in Change

$suppress_localhost = ($wampConf['urlAddLocalhost'] == 'off' ? true : false);
To
$suppress_localhost = ($wampConf['urlAddLocalhost'] == 'on' ? true : false);

OR

2. From Wamp

  1. Right click on wamp icon on tray on the right.

  2. Go to "wamp settings"

  3. Enable "Add localhost in URL"