在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
    // ...
    // ...

  }
}