I'm trying to create a simple form that submits a node with title, body and taxonomy terms entered in by free tagging. My vocab ID is 1 - named "Tags" and I'm trying this form. The node submits with title and body (and user/date) but not the taxonomy. Running Drupal 5.14. What am I doing wrong?
function custom_foo() {
return drupal_get_form('custom_foo_form');
}
function custom_foo_form() {
$form['title'] = array(
'#type' => 'textfield',
'#title' => 'Subject:',
);
$form['body'] = array(
'#type' => 'textarea',
'#title' => 'Body:',
);
$form['taxonomy']['Tags'][$vocabulary->vid] = array(
'#type' => 'textfield',
'#default_value' => $typed_string,
'#maxlength' => 100,
'#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
'#required' => $vocabulary->required,
'#title' => $vocabulary->name,
'#description' => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
function custom_foo_form_submit($form_id, $form) {
global $user;
$form_id = 'resource_node_form';
$node = array(
'uid' => $user->uid,
'name' => $user->name,
'type' => 'resource',
);
$form_values = array(
'title' => $form['title'],
'body' => $form['body'],
'name' => $user->name,
'taxonomy' => $form['taxonomy'],
);
drupal_execute($form_id, $form_values, $node);
}
Comments
Still looking for a solution
So I can add terms in my form easy enough:
$form['tags'] = array('#type' => 'textfield', '#default_value' => $typed_string, '#size' => 60, '#maxlength' => 100, '#autocomplete_path' => 'taxonomy/autocomplete/1');
They just don't save on submit - I'm sure I'm doing something wrong on my submit function - I just don't know what. Any help would be appreciated...
function custom_foo_form_submit($form_id, $form) {
global $user;
$form_id = 'resource_node_form';
$node = array(
'uid' => $user->uid,
'name' => $user->name,
'type' => 'resource',
);
$vocabulary = $form_values['vocab'];
$form_values = array(
'title' => $form['title'],
'body' => $form['body'],
'name' => $user->name,
'taxonomy' => $form['tags'],
);
drupal_execute($form_id, $form_values, $node);
}
?>
you could take a look at
you could take a look at imagefield_import module. he is doing that. he creates nodes and adds taxonomy/free tagging to it.