By Ddaffyd on
I need to pre-set some values on a form. I have a custom module that sets a menu() link to a custom function to do this. It calls node_form() to save me the work of maintaining the form definition in more than one place. By using node_form() I can not pass parameters to form(), and default form action becomes /mymodule/myfunc/myparam, which does not handle post data.
I am solving this by modifying $_SERVER["REQUEST_URI"] which works, but in my opinion is an ugly hack that I do not like.
Can anyone suggest a better way of setting form "action" parameter?
This is how I handle it (module is called langclassify, my custom operation is addchild which gets 1 parameter - parent node):
case 'addchild':
if (node_access('create', 'langclassify')) {
//TODO Ugly hack to get form action correct
$_SERVER["REQUEST_URI"] = $base_url . '/?q=node/add/langclassify';
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => 'langclassify', 'parent' => arg(2));
drupal_set_title(t('Add language classification sub-node to '
. db_result(db_query("SELECT classificationname FROM {langclassify} WHERE lid = %d", arg(2)))));
langclassify_breadcrumb(arg(2));
$output = node_form($node);
} else { $output = message_access();}
print theme('page', $output);
break;