2

I got a CCK field to select a currency; this field is not required, and the dropdown displays '-None-'. I want to change that.

There's the option to let PHP-Code return the value. It says:

return array(
    0 => array('value' => 'value for value'),
    // You'll usually want to stop here. Provide more values
    // if you want your 'default value' to be multi-valued:
    1 => array('value' => 'value for value'),
    2 => ...
);

So I tried with:

return array(
  0 => array('value' => 'my_text'),   
);

Drupal now tells me:

The PHP code for 'default value' returned Array ( [0] => Array ( [value] => my_text ) ) , which is invalid.

I got a list of 4 currencies to choose from, which are the allowed values in my dropdown. What do I have to do to replace '-None-' with my own default?

1

In order for you to use PHP you must return a simpler array:

return array(
  'value' => 'my_text'
);

Also, if all you want is to set a default value, you don't need to use the PHP option.

  • First, define the allowed values (manually or via PHP, doesn't matter)
  • Then click save
  • Now click edit to go back to the form. Close to the top there will be a "Default Value" fieldset populated with the allowed values. Just select one!
3
  • This solves just part of my problem. When I add 'my_text' in the allowed values list. I can select it as the default one and it shows up but there is still the '- None -' value which I want to replace by a different one. It's just the dummy key for non required inputs that I want to replace. – mantuko Apr 24 '11 at 14:59
  • 2
    Then make the select required? It will have a default so it doesn't matter. If it is not required, then there must be a way to select no value, which in your case is '- None -'. – Berdir Apr 24 '11 at 15:10
  • I actually want a way to select no value but I don't like '- None -'. Is there no way to change it? – mantuko Apr 24 '11 at 15:22
-1

The tip from Alex about doing this without using the PHP option is great. However, remember to set the permissions on the new cck field. Until you have done this, you will not be able to see the "Default Value" box.

.. remembering to do this will save much frustration :-$

1
  • This should really be a comment on the related answer. – Chapabu Nov 16 '12 at 11:49

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.