How to validate links before moving to different location This would be most simple functional question in Drupal 7.
Now below mentioned things are mandatory to do and cant change the functionality.
1) I have created a custom block in module.
2) I have included form like below:-

function usercontent_block_view($delta='') 
{

   $block = array();    
   switch($delta)
   {
     case 'user_front_page' :        
       $block['content'] = drupal_get_form('genre_all_login');                       
     break;
   }
   return $block; 
}


3) Now I have some other content in block but which put me in trouble is shown below:-

function genre_all_login($form) {
  $form['new_user'] = array(
  '#type' =&gt; 'item',
  '#markup' =&gt; l('Add New User','http://www.google.com'),            
    );
    return $form; 
  }


4) So it includes a link which will move me to Google once clicked.
5) Now I want to validate certain content inside the block before user navigates to Google.So if the condition doesn't match then I will stop the user by showing an error message and hence user cannot traverse to Google.

Please tell me if it is possible or should I use different technique to handle this scenario.
You can achieve this using a client side validation. Like below,


Add an ID attribute to the external link

$form['new_user'] = array(
  '#type' =&gt; 'item',
  '#markup' =&gt; l('Add New User','http://www.google.com', array('attributes' =&gt; array('id' =&gt; 'external-link'))),            
);

Add a JavaScript code to validate and preventi the click.

jQuery(document).ready(function() {
  jQuery('#external-link').click(function(event) {
    // Perform your validation. If the validation fails prevent events default behavior.
    validated = false;
    if (!validated) {
      event.preventDefault(); // You can also use return false instead of prevent default.
    }
  });
});



Hope this helps :)