Hello, I am trying to build a simple contact form using the form api but I haven't had much success with db_insert. I don't often post question here so I will start by copying my code in:
/*
* Implements hook_theme
*/
function contact_theme() {
return array(
'contact_nameform' => array(
'render element' => 'form',
'template' => 'contact_nameform',
),
);
}
/*
* Assign the elements of the form to variables
*/
function template_preprocess_contact_nameform(&$variables) {
$variables['contact_nameform'] = array();
$hidden = array();
//Provides variables named after form keys
foreach (element_children($variables['form']) as $key) {
$type = $variables['form'][$key]['#type'];
if ($type == 'hidden' || $type == 'token') {
$hidden[] = drupal_render($variables['form'][$key]);
}
else {
$variables['contact_nameform'][$key] = drupal_render($variables['form'][$key]);
}
}
// Hidden form elements have no value to the theme
$variables['contact_nameform']['hidden'] = implode($hidden);
// Collect all form elements
$variables['contact_nameform_form'] = implode($variables['contact_nameform']);
}
/*
* Implements hook_menu()
*/
function contact_menu() {
$items['contact'] = array(
'title' => 'View the sample form',
'page callback' => 'drupal_get_form',
'page arguments' => array('contact_nameform'),