I'm trying to create a Dropdown field and add it to the User field layout. I've successfully created an empty dropdown field (no options) and added it to the User field layout.

Here is my current code for that:

$subscriptionStatusField = new FieldModel();
$subscriptionStatusField->groupId = 1;
$subscriptionStatusField->name = "Subscription Status";
$subscriptionStatusField->handle = "subscriptionStatus";
$subscriptionStatusField->translatable = false;
$subscriptionStatusField->type = "Dropdown";

What I'm having trouble with is how to add options to the dropdown field. How can I do this programmatically?

  • Your plugin has a FieldType, and in your Field Type class within your getInputHtml method you are rendering the template containing the dropdown code?
    – aran
    Nov 11 '16 at 3:35
  • @aran While that may provide the correct options for the front-end, that doesn't provide any server-side enumeration mechanism. Also, I won't be able to change these options in the future without changing my code.
    – Greg
    Nov 15 '16 at 14:57
  • Are you trying to provide settings for the field type so that the user can add options for the drop-down which are output to the field type's front end drop-down?
    – aran
    Nov 15 '16 at 15:31
  • This may be off-topic, but did you tried this plugin: github.com/lewisjenkins/craft-lj-dynamicfields? Nov 30 '17 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.