How to hide a field based on a specific condition? I have a website for ads, which are either of those:


Regular ads.
VIP ads.


The Regular ads have an additional field "field_adding_make_vip". If the user decides to change a Regular ad to a VIP ad, the user will use the description from that field and send a SMS to a specific number and that ad will become automatically a VIP ad. 

The filter in Views to show the VIP content is a additional field "field_vip_date" that uses a date filter. That mechanism is created with a custom PHP file.

So only left to do is: when the Regular ad becomes a VIP ad, the field "field_adding_make_vip" will be automatically hidden and the VIP ad will have additional field "field_adding_vip_image" that will show a VIP image, so every user will know that the selected ad is a VIP ad.

How can I hide that field and show the VIP image when the ad becomes a VIP ad?

The Regular ad and VIP ad are the same content type (adding). I'm using the field "field_vip_date" as a filter in views by date. Let's say when the date field of a specific node is set to 25 October, that node will be displayed in a VIP block position in the website until 25 of October and the next day it will be automatically removed from that position. That's for a block view position.

In every page node the field "field_adding_make_vip" has a description with the node id how to send the SMS, to be used to make it a VIP ad. The whole idea is when the user sends an SMS with the number ID, the field "field_adding_make_vip" will disappear, because the regular node has become a VIP ad and that node will have an additional field "field_adding_vip_image" that will display an image with a text "VIP".

Somehow the field "field_vip_date" (which is a date field) will have to control the field "field_adding_make_vip". For an example if "node/120" has "field_vip_date" set to 25 October, the field "field_adding_make_vip" will be hidden until 26 October and the field "field_adding_vip_image" will be displayed until 26 October.

Note: I've tried the code from @harshal, but it has errors. The name of my custom module is "custom_alter" and here's the full code:

&lt;?php
function custom_alter_form_alter (&amp;$form, &amp;$form_state, $form_id) {

 $node = node_load($nid);
 $date = date('d/m/Y');
 $todaysdate = strtotime($date);
 $field_date_vip = $node-&gt;field_date_vip['und'][0]['value'];
 $date = date('d/m/y',  $field_date_vip);
 $expirydate = strtotime($date);



If ( $todaysdate &lt;  $expirydate )) {
  //Hide the field adding_make_vip using css
  drupal_add_css(drupal_get_path('module', 'custom') . '/css/hide_field_adding_make_vip.css');
             }
else {
// hide field adding_make_vip using css
  drupal_add_css(drupal_get_path('module', 'custom') . '/css/hide_field_adding_vip_image.css');

}

}
I'm not sure I completely understand what you need. But if I'm correct and you just need to show / hide specific fields in a node based on some other field in that node the hook_field_access should help you.

 /**
 * Implements hook_field_access().
 */
function YOUR_MODULE_field_access($op, $field, $entity_type, $entity, $account) {
  global $user;
  switch ($field['field_name']) {
    case 'field_adding_make_vip':
      if ($node['isVIP'][value]) {  //Is the node VIP?
        return false;  //Show the field_adding_make_vip
      }
      else {
        return true; //Hide the field_adding_make_vip
      }
      break;
  }
    case 'field_adding_vip_image':
      if ($node['isVIP'][value]) {
        return true;
      }
      else {
        return false;
      }
      break;

}