How to embed a form element in a Views view

This is how you can embed forms in to a Views view in Drupal 6 with the module Views Embed Form.

<?php
//Create a hook_views_embed_form
//Needs to be [your module name] + '_views_embed_form' but can exists in a inc file
function mymodule_views_embed_form() {
 
//Set a user permission if needed
 
if (user_access('administer workflow state')) {
    return array(
       
'mymodule_embedded_ticket_form' => t('My form name'),
        );
  }else{
      return array();
//I added this to avoid error message if user has no access to the form
 
}
}

//Create a form, remember it has to be unique to avoid conflicts on multiple rows in a view
function mymodule_embedded_ticket_form(&$form_state, $data, $view_name = FALSE){
 
$form['#cache'] = FALSE;
 
$form['#rebuild'] = TRUE;


 
$form['ticket_row']['assigned_row_'.$data->nid] = array(
  
'#prefix' => '<div class="inline-form-item">',
   
//'#title' => $data->nid, //t('Group user'),
   
'#type' => 'select',
   
'#cache' => FALSE,
   
'#rebuild' => TRUE,
   
'#options' => _get_group_users_options(t("Select Assigned to")),
   
'#default_value' => ($data->node_data_field_bj_assigned_field_bj_assigned_uid > 0 ? $data->node_data_field_bj_assigned_field_bj_assigned_uid : 0),
   
'#weight' => $w++,
   
'#attributes' => array("class" => "mymodule-group-user-selector"),
   
'#ahah' => array(
       
'path' => 'mymodule_tickets/embedded/'.$data->nid."/0",
       
'wrapper' => 'content-div',
       
'method' => 'replace',
       
'effect' => 'fade',
       
'event' => 'change',
        ),
   
'#suffix' => '</div>',
  );

  return
$form;
}

?>

Add the Embedded item to your views fields and select your Embedded form name.

Reference:

http://drupal.org/project/views_embed_form/

http://drupal.org/node/329511

Knowledge keywords: