PHP Options example
PHP Options example
Hi, I have successfully used the Field Options method to get a full list of all the items in a table, but I need to limit the choices.
The comments in the source code, it says this about the Options method:
Get a list of values that can be used for the options list in radio,
select and checkbox inputs from the database for this field.
Note that this is for simple 'label / value' pairs only. For more complex
data, including pairs that require joins and where conditions, use a
closure to provide a query
Unfortunately, I've not been able to find an example of that. Does anyone have any sample code they could provide that will allow me to pull the values out of a database with a where restriction, or something along those lines?
Thanks,
Paul
This question has accepted answers - jump to:
Answers
Hi Paul,
The self referencing join example has an example use of using
Editor->options()
as a closure function. Click the "Server script" tab below the table to see the code.Regards,
Allan
Thank you! I've defined my function, read in my data so that I could filter it, and I can loop through it to format it properly, just like the example. I want this select to have a "None" option, which would insert the record with a null value for that field, but get errors whenever I try to do so. To do that, I'm using this code above the loop that builds $out:
Whenever I try to insert a new record with None selected in the dropdown I get messages like:
It is odd that the error message mentions datetime format, as I don't have any datetime fields, but I think the real error is the Incorrect Integer value, as it appears to be trying to insert the record with 'null' as text.
Any ideas?
I would suggest giving it an empty string value. If you want it to actually be null in the database use the
nullEmpty
set formatter (sincenull
can't be sent using a plain HTTP text parameter).Allan
Thanks allan, this solved that issue!