[drupal-devel] Forms API conversion help
I am in the process of trying to convert the ezmlm module to the new forms API. I am doing this so I can learn the forms API. I am one of the maintainers of the ezmlm module and it is a very, very simple module. Once I learn the forms API fairly well, I will be happy to help other people with their conversion efforts, write more documentation on the API and/or convert more modules. I just need to get it all clear in my head first. However, I'm having some problems converting a simple form in my module. I spent several hours reading all the latest documentation and working on it last night, and I've run into a few things where I am not clear on how it should work. If anyone is willing to give me some help, you can view the before and after code here: http://phpfi.com/82366 Questions: 1. Is the #action key in the first form[] element the right way to specify where to post the form? 2. What's the proper array element index where it says "WHAT_GOES_HERE" for a non-form item message that needs to be injected into the form at that point? Is #markup the right type? Seems like it is. 3. What's the correct #type for my hidden form element? 4. What's the correct form array secondary index for an array of checkboxes? In the old form API, one used names like 'my_checkbox_list][' in order to generate HTML like this: <input type="checkbox" name="edit[my_checkbox_list][]"> How is that done with the new API? Thanks, Chris Johnson 31 hours until I leave for Amsterdam! :-)
I am in the process of trying to convert the ezmlm module to the new forms API. I am doing this so I can learn the forms API. I am one of the maintainers of the ezmlm module and it is a very, very simple module.
Once I learn the forms API fairly well, I will be happy to help other people with their conversion efforts, write more documentation on the API and/or convert more modules. I just need to get it all clear in my head first.
However, I'm having some problems converting a simple form in my module. I spent several hours reading all the latest documentation and working on it last night, and I've run into a few things where I am not clear on how it should work.
I was in the same situation as you, and I've found that when in doubt, it is best to open up form.inc and look for theme_<#type>, e.g. "theme_checkbox", "theme_select". Then you can see what HTML is output. If you still can't figure it out, remember (or look for) a core form that is similar to the one you have, and see how it is made ;). By the way, about your checkboxes... #tree is indeed a way to get arrays, but remember that if possible, you should use the plural checkboxes and radios types. Steven
I was in the same situation as you, and I've found that when in doubt, it is best to open up form.inc and look for theme_<#type>, e.g. "theme_checkbox", "theme_select". Then you can see what HTML is output. If you still can't figure it out, remember (or look for) a core form that is similar to the one you have, and see how it is made ;).
This is not that bad, apart from the small problem that a lot of stuff used in theme_foo is created in _form_builder and you should not set them by hand. Examples are name, id and for most elements (where the user can change them) value, too. Yep, it's better to look around for a similar form and nick the code. Regards NK
participants (3)
-
Chris Johnson -
Karoly Negyesi -
Steven Wittens