OK kinda noob-ish question but im unfamiliar with the programing side of Drupal... Im currently building a Form from scratch in drupal 7 (custom module since im using Form_Panel to arrange my form fields) and i would like to implement the webform API into my code as the submit handler.(This way i can hopefully use webform UI to deal with submissions and viewing results at least) Currently i have all the form fields and a submit button but not much else...

function my_module_menu() {
$items = array();
$items['my_module/form'] = array(
'title' => t('Subscription'),
'page callback' => 'my_module_form',
'access arguments' => array('access content'),
'description' => t('Subscription'),
'type' => MENU_CALLBACK,
return $items;
//some random fields from form API after
////////////////// Submit button
$form['submit'] = array( 
 '#type' => 'submit',
 '#value' => 'Submit',
 '#submit' => array('my_module_my_form_submit'),
return $form;
function my_module_my_form_submit($edit,$form, $form_state) {
drupal_set_message('Submission recieved.');

And thats it.It shows perfectly on site and submit refreshes the page.. What i need to know is which function and methods should i use to get webform or drupal period to save my values(create a db table first?) and display them at the necessary time through whatever links on the site.

1 Answer 1


You want to use hook_schema() in your module.install file to make a database table to store your values. A small stupid logging schema I wrote is as follows:

function idprocessing_schema() {
  $schema['idprocessing_log'] = array(
    'description' => 'webextract process logging',
    'fields' => array(
      'id' => array(
        'description' => 'id of entry',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      'created' => array(
        'description' => 'The Unix timestamp when the entry was made.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      'msg' => array(
        'description' => 'whats going on in the processing',
        'type' => 'text',
        'size' => 'medium',
        'not null' => FALSE,
      'num_students' => array(
        'description' => 'number of students from xpath query',
        'type' => 'int',
        'not null' => FALSE,
    'primary key' => array('id'),
  return $schema;

You then insert into the table as needed with say db_insert() a Database API function of drupal.

      'msg' => $msg,
      'num_students' => $cnt,
      'created' => REQUEST_TIME,

You would want to insert $form_state['values'] by the way in your my_module_my_form_submit function.

  • ok thanks, why do i need $form_state['values'](curiosity purposes)? and do i include this in the .install or .inc file? Feb 6, 2013 at 19:42
  • the form submission values are sent to your submission function in the $form_state array, specifcally the "values" key. ..... so you wont be inserting anything without that :P. the hook_schema() goes in yourmodule.install your form submission function goes in your yourmodule.module file.
    – tenken
    Feb 6, 2013 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.