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:

function custom_alter_form_alter (&$form, &$form_state, $form_id) {

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

If ( $todaysdate <  $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');



2 Answers 2


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
    case 'field_adding_vip_image':
      if ($node['isVIP'][value]) {
        return true;
      else {
        return false;

  • @Petroll Thank you for your answer. I'll post more details in the main thread. Oct 20, 2013 at 12:45
  • Please check my updated thread, 'cos I cannot find a way to open a chat with you. Oct 20, 2013 at 12:59

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.
For the part to disppear the vip image fields after expiry the code is as follows : This is just for a single node.

function module_name_form_alter($form,&$form_state, $form_id) {
    if ($form_id == 'adding_node_form') {
       $nid = $form['nid'] ;
       $node = $node_load($nid);
$form['#submit'][] = 'adding_node_form_after_submit';
    //insert the code here


function adding_node_form_after_submit ($form, &$form_state) {
$field_vip_date = $form['field_vip_date']['und'][0]['date'];
$expiry_date = strtotime($form['field_vip_date']['und'][0]['date']);
$date = date('d/m/Y');
$current_date = strtotime($date);
if ($current_date > $expiry_date) {
drupal_add_js( drupal_get_path('module', 'your_module_name') . '/' . custom.js);

Now add a js file in your custom module folder. In your custom.js the code goes as follows:

(function ($) {

  Drupal.behaviors.exampleModule = {
    attach: function (context, settings) {
   // add your code here

  • I cannot understand where to put this code. Oct 20, 2013 at 16:36
  • u should use it inside hook_form_alter()
    – harshal
    Oct 20, 2013 at 18:08
  • I've edited my first post. Please check it. Oct 20, 2013 at 18:48
  • check for the form_id and set the condition as given above in edited answer
    – harshal
    Oct 21, 2013 at 4:07
  • can you send me your email, so I can send you the link of the website, because I think that we are going in a wrong direction. I didn't find a way to chat with you here. Oct 21, 2013 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.