drupaldrupal-6drupal-modulesdrupal-formsdrupal-form-submission

Drupal 6 Form API - Passing Values


I'm trying to write a custom module in Drupal 6 and trying to add a simple-ish form in the admin area using the form API.

I've got the form showing but can't seem to get the from to populate itself again when submitting and then reloading the page. I tried passing in a second parameter of &$form_state to my hook_form function but it results in an error about a missing 2nd parameter.

I'm sure this is something simple but I can't quite figure it out, here's my .module code:

/*
* Implements hook_init().
*/

function movehub_featured_links_block_init() {

    drupal_add_css(drupal_get_path('module', 'movehub_featured_links_block') . '/assets/css/movehub-featured-links-block-style.css');

}

/**
* Implements hook_theme().
*/

function movehub_featured_links_block_theme() {

    return array(
        'movehub_featured_links_block_manage' => array(
            'template' => 'movehub-featured-links-block-admin-manage'
        ),
        'movehub_featured_links_block_add' => array(
            'template' => 'movehub-featured-links-block-admin-add',
            'arguments' => array('link_id' => null)
        ),
    );

}

function movehub_featured_links_block_manage() {

    return theme('movehub_featured_links_block_manage');

}

function movehub_featured_links_block_add_form(&$form) {print_r($form);

    $form = array();

    $form['#attributes'] = array('enctype' => 'multipart/form-data');

    $form['link_title'] = array(
        '#type' => 'textfield',
        '#title' => t('Link Title')
    );

    $form['image'] = array(
        '#type' => 'file',
        '#title' => t('Image')
    );

    $form['image_hover'] = array(
        '#type' => 'file',
        '#title' => t('Hover Image')
    );

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Add!')
    );

    return $form;

}

/**
* Implements hook_menu().
*/

function movehub_featured_links_block_menu() {

    $items = array();

    $items['admin/featured_links'] = array(
        'title' => 'Featured Links',
        'description' => 'Add, view and edit featured links..',
        'page callback' => 'movehub_featured_links_block_manage',
        'page arguments' => array('movehub_featured_links_block_admin'),
        'access arguments' => array('administer movehub_featured_links_block settings'),
        'type' => MENU_NORMAL_ITEM,
    );

    $items['admin/featured_links/manage'] = array(
        'title' => 'Manage',
        'description' => 'Add, view and edit featured links.',
        'page callback' => 'movehub_featured_links_block_manage',
        'page arguments' => array('movehub_featured_links_block_admin'),
        'access arguments' => array('administer movehub_featured_links_block settings'),
        'type' => MENU_NORMAL_ITEM,
    );

    $items['admin/featured_links/add'] = array(
        'title' => 'Add',
        'description' => 'Add a new featured link.',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('movehub_featured_links_block_add_form'),
        'access arguments' => array('administer movehub_featured_links_block settings'),
        'type' => MENU_CALLBACK
    );

    return $items;

}

function movehub_featured_links_block_add_form_submit($form, &$form_state) {



}

function movehub_featured_links_block_add_form_validation($form, &$form_state) {



}

Solution

  • Managed to find the very simple error that caused me this issue - namely that I had used the wrong hook name when validating.

    I had used:

    movehub_featured_links_block_add_form_validation
    

    It should be:

    movehub_featured_links_block_add_form_validate
    

    The key part being the use of hook_validate instead of hook_validation. Rookie error.