Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Rac7hel on
How do I use PHP code to create my Allowed Values List for a particular Field? I'm super new to Drupal, probably missing something obvious, but when I type code into the Allowed Values List box it just spits out my code as the available values. I've looked around and people talk as if it's doable, so, how d'ya do it??
Thanks!
Rachel
Comments
You mean select list ? If you
You mean select list ?
If you are using CCK field then you can add as many numbers of values per line in the text area given for select list. Like -
AF|Afghanistan
AL|Albania
DZ|Algeria
AS|American Samoa
AD|Andorra
If you are using webform then use option_element.
If you have some thing other in mind then please elaborate.
Thanks,
RajeevK
Rajeev Kumar,
@drupler@bihar.social (ActivityPub)
Thanks for your reply. I do
Thanks for your reply. I do mean select list. But I don't want to manually add all those
AF|Afghanistan
AL|Albania
things. I want a dynamic list that pulls things from my database. Is that possible? Or is there another way to do it?
Try this
I've not specifically done this myself but here's my theory....
I think if you get your php to "print" the same thing then you should able do it, e.g:
Same problem
It still doesn't evaluate the code. It just treats each line like text, and changes it to this:
|?>
It did the same thing with the return statement scenario. :S
Use the php code field
I've had another look at this for you I see we need to use the PHP code field rather than the allowed values list text box. To do PHP code you need to click the "PHP code" link then enter stuff in the "Code:" field.
Note you don't need the
tags and it should return a value not print it like this:
Hope that helps
Where
Where exactly is this elusive "PHP code" link and field? The only box I have is the Allowed Values List.
Hi Rac7hel, I am trying to do
Hi Rac7hel, I am trying to do the same thing, I figured out that you need the CCK module for the PHP code field to come up. This adds stuff to fields that are not in core.
Thank you!
That's what I needed to know. Thanks :D
This may not be what you
This may not be what you need for you particular app, but I noticed that you are building a countries list. Drupal 7 core has lists for countries, states, and several other fields that you can access by telling Views (or where ever you have defined the field) to use one of the predefined lists.
Just hoping that this might get you what you need without so much effort.
The countries list was just
The countries list was just an example, but thanks anyway :)
Just to wrap it up (Drupal
Just to wrap it up (Drupal 7):
If you need to create the Allowed Values List dynamically (form a PHP funtion)
So i.s.o.
you want this:
Thanks
thanks, i need this code too
How to make list with NULL, I
How to make list with NULL, I need to let users select empty field and I don't want anything inserted instead, I tried but it shows in views, I want there to be nothing at all, how to do that?