I'm not certain if this is the completely correct forum to place this in, but it seems the closest to me at the time.

The question revolves around something I discovered during 6.x module development.


function mymod_theme()
{
  return  array ( 'mymod_something' =>array ( 'template'  =>'mymod-something'
                                          ,   'arguments' =>array ( 'myarg' =>NULL )
              , );
}

function mymod_block($op = 'list', $delta = 0, $edit = array ( ))
{
  $block = null;

  if ('list' == $op)
  {
    $block  = array ( 0 =>array ( 'info'=>t('Something Block') )
                  , );
  }
  ...

  elseif ('view' == $op)
  {
    $block = array ( );
    $start = _mymod_calculate_arg();

    switch ($delta)
    {
      case 0:  $block['content'] = theme('mymod_something', $start); break;
      default: 
    }
  }
  return $block;
}

function template_preprocess_mymod_something(&$vars)
{
  $vars['content']  = drupal_get_form('mymod_something_form', $vars['myarg']);
}

function mymod_something_form($form_state = array ( ), $myarg)
{
  $form = array ( '#action'    =>url($_GET['q'])
              ,    '#id'       =>'something-form'
              ,    '#submit'   =>array ( 'mymod_something_submit' )
              ,    '#validate' =>array ( )
              , );
   ...
}

function mymod_something_submit($form, &$form_state)
{
  $mylocal = $form['#parameters'][2]; // the $myarg from above ...

  ...
}

So I have few questions about the above code.

#1) It is apparent that the $form['#parameters'] is populated in the mymod_something_sumbit function from the mymod_something_form call's second argument. What isn't apparent is if this is designed to be a means of passing "hidden" information to the mymod_something_submit call, without using a form input element. If so, then that's great.

#2) Is this the "Drupal" way to do things? or am I mucking with something that might disappear tomorrow? I ask because I haven't been able to find a single example of this in the forums or examples on the Drupal sites. (BTW: searching for '#parameter' works as if you searched for 'parameter', and I haven't the time to search all of the results, but after 15 pages I figured I could say no examples :D )

#3) Is it correct that the value of $mylocal in the submission handler is from the original invocation value $start?

Thanks Jeff

Comments

nevets’s picture

From form.inc

// We store the original function arguments, rather than the final $arg
// value, so that form_alter functions can see what was originally
// passed to drupal_retrieve_form(). This allows the contents of #parameters
// to be saved and passed in at a later date to recreate the form.

jefkin’s picture

Great! That answers #1 and #3 clearly.

I hate to put upon the community about work that I don't have time for myself, but it might be worth a mention or two in the Documentation sections of the site.

Jeff