在drupal如何添加名称textfield到简单的新闻块 [英] In drupal how to add name textfield to simple news block

查看:134
本文介绍了在drupal如何添加名称textfield到简单的新闻块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在drupal如何添加名称字段到简单的新闻块。如果我们安装简单的新闻模块,我们可以得到一个电子邮件字段,单选按钮订阅取消订阅和保存按钮。我可以添加名称和文本框

In drupal how to add name field to simple news block.If we install simple news module we can get a email field,radio buttons Subscribe Unsubscribe and save button .how can i add Name and text box

推荐答案

您可以使用hook_form_alter()添加名称字段。您还需要添加一个提交处理程序,以便可以将该名称存储在数据库中。这样的...

You can add a Name field using hook_form_alter(). You will also need to add a submit handler so you can store the name in the database. Something like this...

function mymodule_form_alter(&$form, &$form_state, $form_id) {  
  switch($form_id) {  
    case 'simplenews_block_form_5':// <-- change 5 to the ID of your newsletter  
    $form['name'] = array(  
      '#type' => 'textfield',  
      '#title' => t('Name'),  
      '#required' => TRUE,  
      '#size' => 20,  
      '#weight' => 1,  
      );  

     // Add submit handler so we can store the name
      $form['#submit'][] = 'mymodule_simplenews_block_form_submit';
    break;
  }  
} 

function mymodule_simplenews_block_form_submit($form, &$form_state) {
  if ($form['#id'] == 5) {
    $name = $form_state['values']['name'];
    // Do something here to store the name in the database
    // ...
    // ...

  }
}

这篇关于在drupal如何添加名称textfield到简单的新闻块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆