1

I have two links to redirect based on if a field is empty or not. Now I use the Global text setting to create a link for redirection with A basic <a> tag.

How can I add PHP code in a view to verify the field is empty?

1

First, install the Views PHP module and you can now add a "Global: PHP field" to your views that can include PHP code.

Then add your condition field first in your view and after that your PHP field, so that the condition field value is included in available tokens.

The code of your PHP field should be sth like this:

  <?php    
      if ($field_test) { // use the field token here and check if empty
       return '<a href="$url1">Exists</a>'; 
      } else { 
       return '<a href="$url2">Not exists</a>'; 
      }  
   ?>

See also:

How can I enable Global: PHP field

add Global PHP code field to Views on condition

  • Thanks, But I was asking about if I can do it in Global: Custom text. I have used Views PHP for sure, but was looking if I could do it by other means. – Rony Samuel Apr 4 '18 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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