Hi Stackoverflow community,
I am creating a voting system with many categories using the FormAPI.
I built the form with drupal_get_form() and stored the html markup into a textarea in a CCK field. I also built the submit function which deals with the database.
However, when I display the node, the form can be construct however, the submission function is not called. I can't figure out the source of the problem. Any advice is appreciated, thanks!
*EDIT:
Defines the form:
function judges_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'view':
...
$node->field_judging_form[0]['value']=drupal_get_form('judges_entry',($node));
node_save($node);
}
}
function judges_entry($form_state, $node){
...
return $form;
}
Then I'm simply using CCK to display the form as plain text.
Each time you call drupal_get_form()
a new token is generated (for security reasons), so you can't render a form statically into a field and expect it to ever work.
What you need to do is get a fresh version of the form every time you display it by implementing hook_preprocess_node and then outputting the form in your template file. Something like this in your module file:
function MYMODULE_preprocess_node(&$vars) {
$vars['my_form'] = drupal_get_form('judges_entry',($vars['node']));
}
Then in your template file (node.tpl.php):
echo $my_form;
Hope that helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.