Tuesday, September 29, 2015

filter_input list in php

These are the filter_input list which is very useful. 


    [0] => int
    [1] => boolean
    [2] => float
    [3] => validate_regexp
    [4] => validate_url
    [5] => validate_email
    [6] => validate_ip
    [7] => string
    [8] => stripped
    [9] => encoded
    [10] => special_chars
    [11] => unsafe_raw
    [12] => email
    [13] => url
    [14] => number_int
    [15] => number_float
    [16] => magic_quotes
    [17] => callback

Wednesday, September 23, 2015

Set limit of selection in multiple select box in html

HTML code
<select multiple id='testbox'>
      <option value='1'>First Option</option>
      <option value='2'>Second Option</option>
      <option value='3'>Third Option</option>
      <option value='4'>Fourth Option</option>
      <option value='5'>Fifth Option</option>
      <option value='6'>Sixth Option</option>
      <option value='7'>Seventh Option</option>
      <option value='8'>Eighth Option</option>
      <option value='9'>Ninth Option</option>
      <option value='10'>Tenth Option</option>
    </select>

JavaScript code
var last_valid_selection = null;
      $('#testbox').change(function(event) {
        if ($(this).val().length > 5) {
          alert('You can only choose 5!');
          $(this).val(last_valid_selection);
        } else {
          last_valid_selection = $(this).val();
        }
      });

Output



Sunday, September 13, 2015

validate each and every form in entire application with same javascript code with individual error message

Have a look


JavaScript Code


$('body').on('click', '.btn_class', function(event) {
var bnt_cntrl=$(this).attr('id');
var form_elmnt= $(this).parents('form.form1');
var action=form_elmnt.attr("action");
var error_msg_box=form_elmnt.find('.errorBox');
//alert(error_msg_box);
is_done=0;
form_elmnt.find('.errorBox').empty().append('<ol/>');
form_elmnt.find(':input[is_required="1"]:not(:disabled)').each(function(index, element) {
//alert(1);
var type = this.type || this.tagName.toLowerCase();
//alert(type);
if(type=="select-one"){ 
var currencty_id=$(this).attr("id");
var is_empty=$("#"+currencty_id+" option:selected").val();
}
else{ 
var is_empty=$(this).val();
 }
if(is_empty=="" || is_empty==null || is_empty=='Na' || is_empty=='Null' || is_empty==0){ // if null keyword specified as string 
var error_msg=$(this).attr('err_msg');
if(error_msg=="" || error_msg==null || error_msg=='undefined'){ // if your error_msg and placeholder are same then just skip error_msg tag
error_msg = $(this).attr('placeholder');
}
error_msg_box.find('ol').append('<li>'+error_msg+'</li');
is_done++;
//window.scrollTo(0,0);
false;
}
});
if(is_done==0){
var ajaxMsg='';
error_msg_box.empty();
error_msg_box.append("<div class='welcome_msg'><h3>Please wait.form is beinging submited</h3></div>").slideUp(100).slideDown(50);
var form_data=$(form_elmnt).serialize();
ajaxResponce=send_request(bnt_cntrl,'controller/ajax.php',form_data,error_msg_box);
try {
     JsonDataSet  = JSON.parse(ajaxResponce);
     ajaxMsg      = JsonDataSet[0];
   var ajaxValue    = JsonDataSet[1];
} catch(e) {
    ajaxMsg=ajaxResponce; // if server return only string 
}

if(ajaxMsg=="done"){
var custom_msg='';
if(bnt_cntrl=='add_new_client'){
var timing=1000;
custom_msg="New Client has been added";
error_msg_box.addClass('doneMsg').html(show_done_msg(custom_msg,'?r=add_office&client_id='+ajaxValue+'&lock=1',true,timing)); // page will be redirect after 5 second
$('.redirect_to').html('page will be redirect in '+timing+' milisecond');
}
else if(bnt_cntrl=='add_new_office'){
                 custom_msg='<h2>New office has been created now.</h2>\
<p>Would you like to add More Offices</p>\
<a href="javascript:void(0)" data-role="yes" id="yes_add_more_office">Yes</a>\
<a href="javascript:void(0)" data-role="no" id="no_more_office">no</a>';
$(this).attr('disabled','disabled');
/*var table_elmnt=$('.add_office_table tbody');
var this_region=form_elmnt.find('#regionBox option:selected').text();
var this_country=form_elmnt.find('#country option:selected').text();
var this_zip=form_elmnt.find('#zip').val();
var this_entity_name=form_elmnt.find('#entity_name').val();
table_elmnt.append(
'<tr>\
<td><!--it will auto append by re_arrange Method --></td>\
<td>'+this_region+'</td>\
<td>'+this_country+'</td>\
<td>'+this_zip+'</td>\
<td>'+this_entity_name+'</td>\
<td><i class="fa fa-minus-circle temp_office_row"></i></td>\
</tr>'
);
var panel_1=form_elmnt.find('.form_elements');
var panel_2=form_elmnt.find('.status_elements');
togglePanel(panel_1,panel_2); 
panel_2.html(custom_msg);
re_arrange(table_elmnt,'input[name="is_office_added"]'); */
}
else if(bnt_cntrl=='add_new_employee'){
custom_msg="New employee has been added";
error_msg_box.addClass('doneMsg').html(show_done_msg(custom_msg,'',false,timing)); // page will be redirect after 5 second
//$('.redirect_to').html('page will be redirect in '+timing+' milisecond');
}
//error_msg_box.addClass('doneMsg').html(show_done_msg('sudhir','?r=abcd'));
/*
error_msg_box.addClass('doneMsg').html('<div>\
<i class="fa fa-check-circle bigTick"></i>&nbsp;\
<h2>'+custom_msg+'</h2>\
<i class="btmGap">\
<a href="javascript:void(0)" onclick="javascript:location.reload()">\
Click here to reload page\
</a>\
</i>\
</div>');
*/
$(this).attr('disabled','disabled');
form_elmnt.find('.client_elmnt_box').slideUp(1);
//$('.client_elmnt_box').slideUp(100);
}
else{
error_msg_box.html(ajaxMsg);
return false;
}
}
else{
error_msg_box.show(100);
}
});

HTML form

 <form action="#" class="form1">
       <div class="form_elements">

<div class="col-md-6">
                            <div class="form-group">
                                <div class="input-icon">
                                <label class="txt-normal">Office In time<?php echo star_mark;?></label>
                                <i class="fa fa-clock-o"></i>
                                <input name="office_open_time" value="" type="text" class="form-control" id="opt1" placeholder="enter office opening time as hhmmss skg" is_required="1" err_msg="enter your custom_msg here" />
                                </div>
                            </div>
                        </div>
</div>
</div>
</form>

Sunday, September 6, 2015

how to make a php file with executable array

In this Article, i am trying to make a model file (php ) for table called user_table.

file will  be save in table_name.php


<?php
public function create_model($dataSet=""){

$table_name=$dataSet['table'];
$str_open='<?php $'.$table_name.' = ' ;
$get_table_info=array();
//$str.='$'.$table_name.'=array(';
$table_info=new general;
$get_table_info=$table_info->get_table_schema($table_name); // fetch table column from database
$str_close=' ?>';
$new_model_file_name=__DIR__.'/../model/'.$table_name.'.php';
try{
$done=file_put_contents($new_model_file_name, $str_open.' '.var_export($get_table_info, true).'; return $'.$table_name.'; '.$str_close);
//echo 'Model <b>'.$table_name.'</b> has been created';
echo 'done';
}
catch(Exception $e){
echo 'oops there is some error to write new model';
}

/*
$b=include_once($new_model_file_name);
echo '<pre>';
print_r($b);
echo '</pre>';*/
}
?>

Saturday, September 5, 2015

How to make responsive (YouTube) frame

Dear friend,
However embedding an Iframe is not good as per SEO. but i will tell you the technique to add responsive Iframe.

1. HTML Code

<div class="embed-player">          
                    <div class="h_iframe">
                       <img class="ratio" src="http://bhojpuritrain.com/ico/loading.png" />
<script>
document.addEventListener("DOMContentLoaded", function(event) {
get_player('<?php echo $_REQUEST['v']?>') //do work
});
                            </script>                    
                    </div>
                    <div class="total_view">Total Views-:
                        <?php echo ($video_details['total_views']+1); ?>
                    </div>
                    <div class="description">
                        <?php echo preg_replace('/[^\x20-\x7E]/', '',$video_details['description']); ?>
                    </div>
                </div>



2. CSS

.h_iframe {
position: relative;
height:auto;
}

.h_iframe .ratio {
display: block;
width: 100%;
height: auto;
}

.h_iframe iframe {
/*position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
*/

width: 100%;
height: 100%;
min-height: 400px;
}





3. JavaScript Code

function get_player(video_id){
window.setTimeout(function(){
$('.h_iframe').html('<iframe src="https://www.youtube.com/embed/'+video_id+'" frameborder="0" allowfullscreen></iframe>');
},1000) // frame will load after one second
}


Thursday, September 3, 2015

how to put developer codes into blog or website with line number

If you are blogger  or wishing to post any tech blog.. then you must need to put codes with line number in your article.

I made a simple way to get this issue.


Have a look.

http://sudhirgupta.comyr.com/99crashpoint/codeline.php