0

I'm trying to work with Views PHP but for some reason something is going completely wrong. I have a content field called telephone. In this field is a number "06-12345678" now I want to use Views PHP to remove the "-" so I get the number "0612345678".

What I do is I make a view with the field Telephone and a Global: PHP field underneath it. In this Global: PHP field I add the following code to see if it is working.

<?php print $row->field_telephone; ?>

So when I save this field I get the output: "11" instead of 06-12345678.

When I try <?php print $row->field_title; ?> it does give me the suspected output..? What am I doing wrong? How can I solve this?

1
  • Install Devel module and the code kpr($row) will give you the exact structure of $row object. then print the field.
    – M a m a D
    Jul 10, 2015 at 15:23

1 Answer 1

1
$data->field_field_telephone[0]['raw']['value'];

This will give you your value from that field in Views PHP. If you use dpm() from Devel module it will show you that $row->field_telephone is 11. that's the NID.

Try to avoid using Views PHP unless you are doing something too complex for views. And even then you should try to write a custom module to interact with views instead of saving code in the DB.

1
  • Thanks for the tip! Could you please explain why I should avoid Views PHP is it unsafe?
    – Joost
    Jul 11, 2015 at 18:16

Your Answer

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

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