How to add dynamic rule to jQuery validator

"jQuery validator" is  really a very good plugin for validating your web forms on client side. Why I am recommending this plugin is because its flexibility and set of methods which offers complete customization.  Plugin offers lots of different methods so that you can customize it as per your requirement very easily. I have used it in many applications. There are many other jQuery based form validation tools which actually using this plugin as back bone of there plugins.

I was working on one application yesterday in which I need to load some form fields dynamically from AJAX call. In this case once input fields are populated in your form you may need to apply validation rule for these fields. This step is necessary because the original  $("#formId").validate method was initiated during the page load. So how to add dynamic rule to jQuery validator?? check the following solution.

If you want to add validation rule to form which is already loaded then its kind of tricky and you may need to use following function.

$("#synamicFieldId1").rules("add", {validateApp:['parameter1','parameter2']});

You can find the .rules() documentation with more examples here.

Is Twitter a Waste of Time?

Twitter! What is it?

Internet world has one thumb rule these days, If you don't know any thing then there is only one god GOOGLE, so just ask Google. People ask almost everything to Google :). Believe it see the following example.

Take a look at this funny image, I took this screenshot on Google search page with keyword Twitter is a. 
If you look at the first suggestion it says "Twitter is a waste of time". that's so funny. It means people use to search this phrase so many times that Google suggest is giving importance to this keyword more than other keywords. :)



 Lots of friends of mine are not actually using twitter but everyone of them says twitter is just a waste of time. What I think is they just don't know how to use it. Twitter is a invention of micro blogging, and its just cool tool , use it in a right way.


CSS1 vs CSS2 & SEO

This post will help you to understand the primary features in CSS2 which are not there in CSS1 and how CSS2 techniques are going to help you in SEO. CSS1 is published in 1996 and CSS2 is published in year 1998. All major browsers supports practically 99.9% of CSS2. I was googlin for the difference between CSS1 and CSS2 and landed on a very good website and found really dam important information about new tags introduced in CSS2. You can check all of them on this website > http://xahlee.org/js/css2.html.

Google bot and other search engines does consider uncompressed HTML size of your webpage, so even if we are using gzip compression techniques, we have to think about the uncompressed HTML size. One of my website's home page is of size 59.23 kb. The which I used to test my site have suggested CSS2 based layout and its new techniques which really helps a lot to reduce your page size. I am working on some of the new tags implementations which will help me to reduce the size of CSS file as well as my HTML page size.

There are few more CSS techniques which helps us to increase the speed of our website. One of the very popular technique is "CSS Sprites". CSS Sprites is basically a technique which combines all small images on your web page in to one big image. In this case we have to just load a single image instead of loading lots of small images separately, this saves a lot of browsers time to make n no of http requests to server so increases speed of your website.

php best practices 1 - Handle unexpected conditions

Are you handling all the possible conditions under which your programs will run?

For instance, do you always have a "default" case in you "switch" statements?

switch($some_value)
{
case 1:
$another_value = 1;
break;
case 2:
$another_value = 4;
break;
}
return(1 / $another_value);

What if $some_value is not 1 nor 2?

Notice: Undefined variable: another_value

Warning: Division by zero

What about "if" conditions? Do you have an "else" code section to all important "if" statements?

If your program is not expecting certain conditions but those conditions are not impossible to occur, having simple calls to error_log may help you to be aware of the problems under unexpected situations.

switch($some_value)
{
case 1:
$another_value = 1;
break;
case 2:
$another_value = 4;
break;
default:
error_log('unexpected some_value '.$some_value.' found ');
exit;
}

php framework comparison - performance comparisons

I am writing this post regarding PHP framework performance comparisons. There are lots of PHP frameworks available and every framework has its own advantages and disadvantages. As all frameworks are based on MVC and thus adopting any of them for product development is not that difficult. Normally developers check for no of libraries load time and some important features like ORM. Also you can check that which framework supports which php version.

Here is a simple chart which programmers can use while choosing the suitable framework for their projects.



phpframeworks[.]com also have explained this thing in detail. You can check that also.

Jquery plugin to read query string - how to

If you are looking for some jQuery plugin to read the query string parameters then you are on right page. Here is a simple function which will help you to understand how to detect/read the values of query string parameters.

Jquery Plugin

$.queryParam = function(name){

var answer = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);

if (!answer)
{
return 0;
}
return answer[1] || 0;
}


How to use
var paramValue = $.queryParam('paramName');

get X days back date from current date

How to get 7(X) days back date from current date?

PHP is very strong server side programming language which simplifies lots of small small tasks like converting date formats etc.

I was working on some task, where I was suppose to get 7 days back date from current date. Actually the task is very simple, I am sharing the code here. Have a look at it and let me know if any one can find better way than this.


$format = 'YmdhIS'; // YOU CAN USE ANY FORMAT WHICH YOU WANT

$date = date ( $format );

// - 7 days from today
$prevDate = date ( $format, strtotime ( '-7 day' . $date ) );

Note: If you want to get yesterdays date then simply do -1 instead of -7.

How to get 7(X) months back month from current month?

// - 7 months from today
$prevDate = date ( $format, strtotime ( '-7 month' . $date ) );

Its so simple.

Share this post with your friends