In Drupal 7, I am trying to programmatically create a custom content type. I have defined my custom content type implementing hook_node_info()
.
For my node editing form, I am using hook_form()
and defined my custom node's title here. I used hook_form_alter()
to convert my node editing form into a multi-step form, where I used the following code.
if ($step == 4) {
$form['actions']['finish'] = array(
'#type' => 'submit',
#value' => t('Submit'),
);
}
// Add validation handler.
$form['#validate'][] = 'mymodule_form_validate';
// Add submission handler.
$form['#submit'][] = 'mymodule_form_submit';
function mymodule_form_validate($form, &$form_state) {
drupal_set_message(t('validating multistep form'));
}
function mymodule_form_submit($form, &$form_state) {
switch($form_state['triggering_element']['#value']) {
case $form['actions']['next']['#value']: // if 'Continue >>' is clicked.
$step++;
$form_state['rebuild'] = TRUE;
break;
case $form['actions']['finish']['#value']: // if 'Submit' is clicked.
$form_state['rebuild'] = FALSE;
// To Do.
// Store the values from the form in the database here.
drupal_set_message(t('Your form has been submitted'));
break;
}
}
My multi-step form is working great, but I am stuck on my last step of the form, where I save the user submitted values in the database. I am not getting any reference on this topic. I am looking for information on how to save my this node in the database, what hooks to use, and some more details. Please guide me in the right direction.