| 5 node.php | hook_form(&$node, |
| 6 node.php | hook_form(&$node, $form_state) |
| 7 node.api.php | hook_form($node, &$form_state) |
| 8 node.api.php | hook_form($node, &$form_state) |
Display a node editing form.
This hook, implemented by node modules, is called to retrieve the form that is displayed when one attempts to "create/edit" an item. This form is displayed at the URI http://www.example.com/?q=node/<add|edit>/nodetype.
Parameters
&$node: The node being added or edited.
$form_state: The form state array. Changes made to this variable will have no effect.
Return value
An array containing the form elements to be displayed in the node edit form.
The submit and preview buttons, taxonomy controls, and administrative accoutrements are displayed automatically by node.module. This hook needs to return the node title, the body text area, and fields specific to the node type.
For a detailed usage example, see node_example.module.
Related topics
File
- developer/
hooks/ node.php, line 245 - These hooks are defined by node modules, modules that define a new kind of node.
Code
<?php
function hook_form(&$node, $form_state) {
$type = node_get_types('type', $node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
);
$form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
$form['field1'] = array(
'#type' => 'textfield',
'#title' => t('Custom field'),
'#default_value' => $node->field1,
'#maxlength' => 127,
);
$form['selectbox'] = array(
'#type' => 'select',
'#title' => t('Select box'),
'#default_value' => $node->selectbox,
'#options' => array(
1 => 'Option A',
2 => 'Option B',
3 => 'Option C',
),
'#description' => t('Please choose an option.'),
);
return $form;
}
?> Login or register to post comments
Comments
forms_api_reference
For a strange reason I never can't find this page wich is really useful.
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....
Administrative accoutrements?
It did make me laugh.
But as long as we're talking api documentation here, accuracy is important.
As we're not talking additional items of clothing, could this be changed from:
to something like:
I don't think the accuracy is
I don't think the accuracy is affected :)
If you are petitioning for the inclusion of 'workflow options' and 'etc', those could certainly be added:
node content forms
while reading examples and books, it seemed that when you have a module defined node type such as:
$node = array('mynodetype' => array(
'name' => t('MyType'),
'module' => 'mymodule',
'description' => t('My very own node type'),
'has_title' => TRUE,
'title_label' => t('And I Will Call Him ...'),
'has_body' => TRUE,
'body_label' => t('George'),
)
);
that the node form when creating new content would display the defined title and body labels - but they were still showing "Title" and "Body".
in order for my nice labels to show up i had to define hook_form() as
function mymodule_form($node, $form_state) {return node_content_form($node, $form_state);
}
Why this hook generates not
Why this hook generates not unique form ID? For all of them it is "node-form". And how can I change it?