In my module I am building a page in the settings portion. There is a form on this page, then under it I want a table that will list existing entries belonging to the particular setting.
At the end of each row I want to offer a button that would be used to delete the item in that row. It would also need to confirm that the person wants to delete the item.
I'm seeing some examples on how people are building these tables, but I am confused, plus feeling further bewildered at what appears to be a convoluted way of presenting something as simple as what I have described.
Can someone clarify the steps for what I need to do to make this happen? You don't need to provide code, unless you are so inclined. I just need to know how the steps on how to accomplish this.
Meanwhile, I'll keep coding-away and trying to figure this out. I just hate having to write long code to do the simple stuff. :)
CJ
Comments
[deleted]
[deleted]
It's not as easy as you would
It's not as easy as you would probably like. You need to create your elements (essentially your table cells) in your form definition, then use a theme function to create your table. You'll also need to register your theme in hook_theme(). Here's a simple example:
Need to register the theme 'mymodule_myform_table' in hook_theme():
Note - clear your cache.
Finally, the theme function:
Note - not checked. May contain typos.
May I ask
Can this be changed to work with an unknown number of elements which will be changed possibly after each callback? I'm trying to set a var with
but it doesn't work as planned.
Yes, it is possible to make
Yes, it is possible to make the number of elements dynamic. You just have to store the count as you are doing, and use that as a reference.
I wanted it slightly more dynamic
..so I return the table from an ajax callback after I query the db
is this the only way
is this the only way still?
Submit Values
Just wondering how you would access the fields within the submit function for each specific button, as there is no way to pass over the specific $i value you need to access the specific button. Is there any fix to this?