By mvdschoot on
Hi,
I would like to add some custom values to the node_type pages, therefore using:
function mymodule_form_alter(&$form, $form_state, $form_id) {
<snip>
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['node']['per_node'] = array(
'#type' => 'checkbox',
'#title' => t('Enable this setting'),
'#default_value' => mymodule_get_settings('per_node', $form['#node_type']->type),
);
<snip>
}
While editing a node_type, this option is nicely shown. But when I click the 'Save configuration' button, I want to store those values, but how? Which hook do I have to implement to store the value of checkbox along with this content type?
Thanks in advance,
Merijn
Comments
That depends...
You will need to use hook_nodeapi to get your new values into the db.
Not sure if you are overriding existing drupal form values, such as body, or trying to insert data into new tables.
If you are, for example, trying to override the "body" value of a form, you could write something like this:
function hook_nodeapi(&$node, $op, $a3 = null, $a4 = null) {
switch ($op) {
case submit :
$node->body = $mynewvalue;
}
If you are inserting this data into a new table you will need to use hook_insert, which might look something like this:
function hook_insert($node) {
db_query("INSERT INTO {yourtablename} (nid, vid, fieldname) VALUES ('%d', '%d', '%s')",
$node->nid, $node-vid, $node->fieldname);
"fieldname" is your form value field.
HTH. Look over the Form API for more info and examples.
That depends...
You will need to use hook_nodeapi to get your new values into the db.
Not sure if you are overriding existing drupal form values, such as body, or trying to insert data into new tables.
If you are, for example, trying to override the "body" value of a form, you could write something like this:
function hook_nodeapi(&$node, $op, $a3 = null, $a4 = null) {
switch ($op) {
case submit :
$node->body = $mynewvalue;
}
If you are inserting this data into a new table you will need to use hook_insert, which might look something like this:
function hook_insert($node) {
db_query("INSERT INTO {yourtablename} (nid, vid, fieldname) VALUES ('%d', '%d', '%s')",
$node->nid, $node-vid, $node->fieldname);
"fieldname" is your form value field.
HTH. Look over the Form API for more info and examples.