【问题标题】:Not able to make submit button work in form theme in drupal 7无法使提交按钮在 drupal 7 中的表单主题中工作
【发布时间】:2015-02-18 06:49:30
【问题描述】:

我正在尝试开发一个模块,我的表单需要以表格形式呈现。除提交按钮外,一切正常。它既不调用默认的 _validation 或 _submit 函数,也不调用 _form_alter 函数。我不知道我在哪里失踪。

这是我的 .module 文件的代码

<?php 
function mytheme_menu(){
  $items = array();
  $items['enqform']=array(
    'title' => 'Enquiry Form',
    'page callback' => 'mytheme_function',
    'access arguments'=>array('access content'),
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

function mytheme_function(){
  return theme('enquiry')
}

function mytheme_theme() {
  return array(
    'enquiry' => array(
        'render element' => 'form',
        'template' => 'custompage',
    ),
  );
}

function enquiry_form($form, &$form_state){
  $form['efname'] = array(
    '#type' => 'textfield',
    '#title' => 'First Name',
    '#size' => 28,
    '#maxlength' => 10,
    '#required' => TRUE,
  );

  $form['elname'] = array(
    '#type' => 'textfield',
    '#title' => 'Last Name',
    '#size' => 28,
    '#maxlength' => 10,
    '#required' => TRUE, //make this field required
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  return $form;
}

function enquiry_form_validate($form, &$form_state){
}

function enquiry_form_submit($form, &$form_state) {
  db_insert('form_example')->fields(array(
    'efname'=>$form_state['values']['efname'],
    'elname'=>$form_state['values']['elname'],
    'active' => 1,
    )
  )->execute();
}

我的 .tpl.php 页面看起来像这样

<?php$form = drupal_get_form('enquiry_form');?>
<h2>Please enter details here</h2>
<?php print render(drupal_render($form['efname']));?>
<?php print render(drupal_render($form['submit']));?>
<?php print render(drupal_render_children($form));?>

当我在挂钩菜单中使用“drupal_get_form”作为页面回调时,提交工作正常,但模板的用途没有用。如果有人能指导我在这段代码中哪里以及我缺少什么,那将节省一天的时间。

【问题讨论】:

    标签: drupal-7 themes drupal-modules drupal-themes drupal-form-submission


    【解决方案1】:

    我认为你不应该渲染 drupal_render_children,你应该自己打印 drupal_render_children。

    <?php print drupal_render_children($form); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 2014-01-31
      • 2020-04-09
      • 2021-12-29
      相关资源
      最近更新 更多