Howdie there,

Issue is that I can't find the php-code section in a cck content type field. Where one can add some php for a default value. Am i missing something? Checked the permissions and enabled the php code evaluation module. Also using nodereference as a field with autocomplete matching.

Im trying to create a parent child relation ship with some cck.. an I'm in need of the php-code section that seems to be missing... seeing as the modules to create this stuff have not been ported. Thought would be possible to use core to create this stuff... shux.

Comments

primsi’s picture

I didn't find that either. Solved my problem using hook_form_alter().

primsi’s picture

Just found it:

  1. Enable PHP filter module (core)
  2. Go to admin/people/permissions
  3. Enable 'Use PHP for settings' for your role (or the roles you trust)
  4. In the field settings select 'Filtered text (user selects text format)' and then chose PHP code for the Default value imput
Oceanman’s picture

I'm confused. I created a new content type and want a field which is a user reference (to the user creating the content) and want to set the default for this field to the user creating the content. I wanted to add a php snippet for this default creating a link to the user profile who created the content.

I have done these things:

  • Enable PHP filter module (core)
  • Go to admin/people/permissions
  • Enable 'Use PHP for settings' for your role (or the roles you trust)


For a user reference field I have not php snippet option (There is a php code option for the text field but it is open to the user creating the content). I want this to be a fixed default which only the admin can set.

What am I doing wrong?

ropaolle’s picture

subscribe

samwillc’s picture

Hi,

I'm trying to do the same thing. Has the 'php code' expanding option under fields been discontinued in drupal 7 or am I doing something wrong?

I don't mean the php input filter, I can get that working ok to add php to body text etc. I mean the option to add a small custom snippet of code into a cck field, like in drupal 6. Can someone please confirm whether or not this is actually an option in drupal 7 before I pull the rest of my (receding) hair out?!

Thanks,

Sam.

Håvard’s picture

Subscribe!

samwillc’s picture

What does 'Subscribe!' mean? I see it all over these forums and still none the wiser to why people keep writing it. Do you write that just so you get a notification when a new post arrives in this thread?

And while on the subject, how to I get an email notification of topic replies? That doesn't seem to work for me either. My registration details were correct and I still use the same email address.

Sam.

wanghl165’s picture

Subscribe!

samwillc’s picture

lol, like I was saying...

tomogden’s picture

Normally I would usually use a token for that kind of thing. In the default field you would enter something like [user] or [email], and that would do it. However, I'm not sure if the tokens are being looked for in CCK fields, as in other places.

--
Tom/* Ogden

jzornig’s picture

I have enabled the PHP Filter module in core. I have a PHP filter available to admin. but in my field settings i do not see any input filter selection to change from filtered html to PHP code. Are input filters supposed to work on field settings in Drupal 7? Is there some other precondition that I have to set?

jzornig’s picture

You have to install the CCK module for drupal 7. The ability to use php for the field settings is not in drupal 7 core. It is provided by the CCK for drupal 7 module.

my-family’s picture

Thank you, but it does not work.

After enabling above settings, I see, e.g., PHP evaluation in Rules, but NOT in cck fields.

I can input php in longext fields (there is filter selection), but this is NOT my case. I need to add default value for, e.g., text fields, or userreference fields, etc. (something which was so simple in D6). Is it no more possible?

earwax’s picture

The PHP snippet exists, but not for all field types. :(

Isostar’s picture

The proposed solution doesn't work for me either.
I want to use the php snippet to set te default value to a $_GET variable, which was possible in D6.

lily.yan’s picture

I want to use php code to set default value for text field, but I cannot find "php code". thanks for help.

earwax’s picture

You need the CCK module for drupal 6 or drupal 7

pico34’s picture

In the latest module CCK for Drupal 7 (7.x-2.x-dev at this time), the "Default value PHP code" (and the "Allowed values PHP code") is available ! (for an option list field in my case).
I'm looking forward a stable version of CCK module for D7. Anyway, CCK is now a very small module (due to Drupal Core integration), so no pb with activating CCK for D7.

rodrigo panchiniak fernandes’s picture

By default you have to set your field, at manege fields, to "Long text and summary", like body section itself. If PHP filter is enabled, you will get access to it for your custom field.

retiredpro’s picture

its not the "PHP filter" that they're looking for. its the "Allowed values PHP code" in the field settings that is missing. You can use it for situations where rather than defining a list of select or radio/checkbox options, you can use php to create that list for you. I can confirm that installing CCK 7.x-2.x-dev will enable this php override option.

Dennis
oh-soyummy.com

gandhi.pranav.66’s picture

I have a same problem that i can not find PHP code for default value. my field type node reference with select list. i want to do that when page load getting variable from query string and display it in select list it is working in drupal 6 but i want to do it in drupal 7 . i have installed cck module and i have enable php module but i can not find PHP code. m i missing something????

caw67’s picture

is not working for all field types! and there is no more tokens!!!

mikolaskova’s picture

I have the ckk module and php filter installed, but I can not enter php Code into the default field ...
Is it possible to a textfield? How did you solve this?

jwplex’s picture

I got around this issue by creating a small custom module to modify the form on display. This was done with a hook_form_alter on the node create form.

For example, I had a content type "reservation" that I wanted to modify the default date range by taking a value from the query string to set the day. This was the function I used to modify that field "field_time_range". There are probably better ways to do what I needed, but this demonstrates how to add custom php to change the default value of the field.

function customreservation_form_alter(&$form, &$form_state, $form_id)
{
        if ($form_id != 'reservation_node_form')
        {
                return;
        }

        // Test if we have a value on the query string we can set the date to.
        $query = drupal_get_query_parameters();
        if (isset($query["date"]))
        {
                $newdate = date('Y-m-d 14:00:00', strtotime($query["date"]));
                $newdate2 = date('Y-m-d 15:00:00', strtotime($query["date"]));
                $form["field_time_range"]["und"][0]["#default_value"]["value"] = $newdate;
                $form["field_time_range"]["und"][0]["#default_value"]["value2"] = $newdate2;
        }
}
darrellduane’s picture

Thanks for the sample code from hook_form_alter(), jwplex.

This format didn't work for me, but this did:


reg_event_form_alter() {
  global $user;
   if($form_id == 'reg_node_form'){
   
      // code to load  $main_event node  deleted                                                                                                                                                                        
  
           $form['field_reg_user']['und'][0]['uid']['#default_value'] = $user->uid;                                                                
            $form['field_reg_workshifts_required']['und'][0]['value']['#default_value'] = $main_event->field_event_workshifts_required['und'][0]['value'];
        }

Darrell Duane
d@duane.com