Inicio › API reference ›
hook_form
hooks/node.php, line 230
- Versions
- hooks
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.
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.
Parameters
&$node The node being added or edited.
$form_state The form state array. Changes made to this variable will have no effect.
Valor de retorno
An array containing the form elements to be displayed in the node edit form.
Código
<?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,
);
$form['body'] = array(
'#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#rows' => 20,
'#required' => TRUE,
);
$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;
}
?> 
Comentarios recientes
hace 3 horas 5 segs
hace 6 horas 4 mins
hace 12 horas 6 mins
hace 17 horas 58 mins
hace 1 día 22 horas
hace 3 semanas 1 día
hace 4 semanas 7 horas
hace 4 semanas 1 día
hace 4 semanas 2 días
hace 4 semanas 2 días