[support] Simple Module Coding Question

Ivan Sergio Borgonovo mail at webthatworks.it
Wed Jul 30 19:11:37 UTC 2008


On Wed, 30 Jul 2008 20:58:31 +0200
"Fred Jones" <fredthejonester at gmail.com> wrote:

> > What about
> > ...
> >  'path' => 'somepath/'.arg(1).'/'.arg(2),
> >  'callback' => 'drupal_get_form',
> >  'callback arguments' => Array('my_form',arg(1), arg(2)),

> I don't understand you, Ivan. Using:
> 
> 'path' => 'somepath',
> 
> and then calling arg(1) will yes only work at a URL of the form:
> 
> somepath/x
> 
> but your solution also only will work at a URL of the form:
> 
> somepath/x/y


In the hook yes... but at least you can reuse the form generating
function elsewhere.

Specifying the path with arguments in the menu_hook is a form of
"input validation".
If you don't need it... or you'd like to rely on default param
etc... you could simply:

'path' => 'somepath',
'callback' => 'drupal_get_form',
'callback arguments' => Array('my_form',arg(1), arg(2)),

...

but still you could use my_form elsewhere... maybe in another hook
or as part of a more complicated page or merged with other forms of
modified through form_alter etc...

To be extraclear

function my_form($form_values) {
  $mystuff=(int)arg(1)*(int)arg(2);
}

is much less flexible than

function my_form($a, $b, $form_values) {
  $mystuff=$a*$b;
}

and you could even wrap input validation elsewhere.


-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it



More information about the support mailing list