Hi,

Does anybody know what is the best method (if there is a method) to add a custom form that can be submitted, on a node edit page? My guess is using form_alter(), but I don't know if this is gonna work and is the best way to do that.

Thanks!

Comments

maheshg85’s picture

I dont know when you want to add the custom form there are two scenarios
1. When user viewing the node ,url eg is : www.xyz.com/node/{nid}
2. When node owner of the node is editing the node, url eg is : www.xyz.com/node/{nid}/edit

In first case you need to use

 function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {    
    case 'view':
       if ($node->type == 'your content type') {
            // you need add custom form field which has a #type  => 'item' to that content type using hook_form_alter
           $node->content['custom_form_field'] = array(
                         '#value' => drupal_get_form('your_custom_form), 
              );
       }
  }
}

In second case Use hook_form_alter and switch to your content type node form case

function hook_form_alter(&$form, $form_state, $form_id){
  global $user; 
   
     switch($form_id){
	   case 'your_content_type_node_form':
	         $form['custom_form_field'] = array(
                    '#type' => 'item', 
                    '#value' => drupal_get_form('your_custom_form'),
                  );
		

Hope this works ,Try out