I have a form:

function form_search_products($form, &$form_state) {
  $form = array();

  $form['keyword'] = array(
    '#type' => 'textfield',
    '#description' => 'Enter keywords (ie: Fat free milk)'

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Add item to my shopping list'

  return $form;

Simple and its loaded into a block region above product listings via:

function products_block_view($delta = '') {
 $block = array();

  switch ($delta) {
    case 'search_form':
      $block['content'] = drupal_get_form('form_search_products');
  return $block;

I am trying to figure out how to map a submit handler now as there is no menu...

My current menu looks like this:

function products_menu() {
  $items = array();

  $items['products/mycity'] = array(
    'type' => MENU_CALLBACK,

    'title' => 'Enjoy shopping in MyCity',

    'page callback' => 'html_list_products',      
    'access arguments' => array('access products')

  $items['products/autocomplete.json/%'] = array(
    'type' => MENU_CALLBACK,

    'page callback' => 'json_list_products',
    'page arguments' => array(2),
    'access arguments' => array('access products')

  return $items;

What or how do I add to the menu_hook above so that I can process form submissions done through the above block code???



Form submissions aren't dependent on there being a path to view/submit the form at, all you need to do is one of the following:

  1. Name the submit function as FORMNAME_submit() and Drupal will pick it up automatically
  2. Add the handler manually in the form function itself, e.g.

    $form['#submit'][] = 'my_submit_function';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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