I developed a form that contains a list of users with checkboxes. This form simply saves the selected user IDs to the database.

Now I try to replace that simple list of checkboxes with a View that shows a list of users in a table, containing checkboxes in the first column and different data (name, email, custom fields) in other columns. What's more, I need that site administrator can adjust the View as he wants: change display style, rearrange columns, etc. (i.e. hardcoding the list of columns is not the way out).

I investigated the Views Forms API (https://api.drupal.org/api/views/help%21api-forms.html/7, https://www.isovera.com/blog/programmatically-creating-forms-views-drupal-7) and managed to create a dummy checkbox field by implementing views_handler_field. It looks perfect when I output it through $view->execute_display(...) in '#markup' element of my form, but the form doesn't actually work.

Has anybody an idea how to embed the form (appeared thanks to views_form(&$form, &$form_state) method) into my own form? Any suggestions or directions to investigate, please..

Thanks,
Alexander

Comments

ayesh’s picture

You will need to create your own custom ews handlers for that. Have a look at views_bulk_operations module. I think it does what you are trying to do more or less.

Chewits’s picture

Hi Ayesh,

VBO only creates and overrides a form over the View using Views Form API - I have already made this part of work. I may even use VBO as a dependency for my module because it makes the job better..
But my question is how can I embed that form into another form (which has some other form elements) so that I can catch selected IDs in my_module_form_submit(...).

Alexander

jaypan’s picture

You can't really embed one form in another in Drupal. The best you can do is call the form definition to get the form array, but you won't get the submit or validation functions along with it, you'll need to manually add those.

Contact me to contract me for D7 -> D10/11 migrations.