I’m new to developing Drupal 7 modules, and I can’t figure out why my custom module’s form data is not stored in my database’s table called ‘media_skins‘.
I followed the info explained in Creating modules – a tutorial: Drupal 7.x but I can’t get it working. What’s wrong with my code?
Here’s my code:
function media_skins_menu() { $items = array(); $items['admin/config/content/media_skins'] = array( 'title' => 'Media Skins', 'description' => 'Configuration for Skins module', 'page callback' => 'drupal_get_form', 'page arguments' => array('media_skins_form'), 'access arguments' => array('access administration pages'), 'type' => MENU_NORMAL_ITEM, ); return $items; } function media_skins_form($form, &$form_state) { $form['media_skins_test'] = array( '#type' => 'textfield', '#title' => t('Test field'), '#size' => 20, '#maxlength' => 20, '#description' => t('Test info for the field.'), '#required' => FALSE, ); return system_settings_form($form); } function media_skins_form_validate($form, &$form_state) { // For now, I will no validate anything } function media_skins_form_submit($form, &$form_state) { $form = db_insert('media_skins')->fields( array( 'start_date' => $form_state['values']['media_skins_test'], ) ) ->execute(); drupal_set_message('Data stored in database successfully'); }
Any help will be very appreciated.
EDITING THE SCENARIO
After reading your comments, I tried the following, but I get “Unexpected error, try it again”:
function media_skins_form($form, &$form_state) { $form['media_skins_test'] = array( '#type' => 'textfield', '#title' => t('Test field'), '#size' => 20, '#maxlength' => 20, '#description' => t('Test info for the field.'), '#required' => FALSE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Enviar'), ); return $form; }