[support] FormAPI, multiple versions of a form on the same page
Anders
fajerstarter at gmail.com
Sat Oct 14 13:24:23 UTC 2006
I'm creating a module which adds a rating form to all comments, much
like the mediumvote/simplevote, except that I wan't to use a form
instead of links to submit the ratings.
The problem I'm having is when several comments are displayed on the
page, all having a rating form, only the first form works as expected.
I guess it's makes sense since they all have the same form_id, and I
haven't found a way to alter the id. I'm sure there are some clever
ways of solving this with the formAPI, any tips or pointers to modules
already doing this (both for 4.7 and 5.0 are welcome)?
Here is my form code (short version) which gets inserted to the
comment with drupal_get_form('mymodule_rate_form', $record).
function mymodule_rate_form($record) {
$form['options'] = array(
'#type' => 'select',
'#options' => array(NULL => t(''), 1 => t('good'), 2 => t('bad')),
);
$form['cid'] = array(
'#type' => 'value',
'#value' => $record['cid'],
);
$form['submit'] = array(
'#type' => 'submit',
'#value' =>t('Rate'),
);
return $form;
}
And the code to submit the form:
function mymodule_rate_form_submit($form_id, $form_values) {
$cid = $form_values['cid'];
$value = $form_values['options'];
//Do some voting here
}
Thanks,
Anders
More information about the support
mailing list