In drupal come aggiungere nome textfield a semplici blocchi di notizie

In drupal come aggiungere il field nome al block notizie semplice.Se installiamo un module news semplice possiamo get un field email, pulsanti radio Iscriviti Annulla iscrizione e salva il button .come posso aggiungere Nome e casella di text

È ansible aggiungere un field Nome usando hook_form_alter (). Sarà inoltre necessario aggiungere un gestore di invio in modo da poter memorizzare il nome nel database. Qualcosa come questo…

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'] = arrays( '#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 // ... // ... } } 

Usa invece il module webform

Crea un file chiamato simplenes.inc nella directory module / webform / componente e copia il codice qui sotto. Avrai un nuovo componente Webform chiamato "simplenews". È quindi ansible select la newsletter a cui questo field deve iscriversi.

Questo non è stato pesantemente testato, usarlo a proprio rischio.

 <?php function _webform_submit_simplenews(&$data, $component) { $news_vid = $data[0]; $email = $data[1]; if($email && $news_vid) { simplenews_subscribe_user($email, $news); } } function _webform_edit_simplenews($currfield) { if (!module_exists("simplenews")) { drupal_set_message(t("Using simplenews components in webform requires the <a href='http://drupal.org/project/simplenews'>Simpnews</a> module."), "error"); } $edit_fields = arrays(); $options = arrays(); foreach( taxonomy_get_tree(_simplenews_get_vid()) as $newsletter) { $options[$newsletter->tid] = $newsletter->name; } $edit_fields['extra']['newsletter'] = arrays( '#type' => 'select', '#title' => t("Newsletter"), '#default_value' => $currfield['extra']['newsletter'], '#description' => t('Select which newsletter can be chosen'), '#required' => TRUE, '#multiple' => FALSE, '#size' => sizeof($options), '#options' => $options, ); $edit_fields['mandatory'] = arrays( '#type' => 'hidden', '#value' => 1, ); $edit_fields['extra']['description'] = arrays(); // Hide the description box return $edit_fields; } function _webform_render_simplenews($component) { $form_item[] = arrays( '#type' => 'hidden', '#value' => $component['extra']['newsletter'], ); $form_item[] = arrays( '#title' => htmlspecialchars($component['name'], ENT_QUOTES), '#type' => 'textfield', '#required' => 1, '#validate' => arrays('_webform_validate_email' => arrays('submitted]['. $component['cid'])), ); $form_item['#weight'] = $component['weight']; return $form_item; } function _webform_submission_display_simplenews($data, $component) { $form_item = _webform_render_hidden($component); $form_item['#value'] = $data['value']['0']; $form_item['#type'] = 'textfield'; $form_item['#title'] = htmlspecialchars($component['name'], ENT_QUOTES) ." (hidden)"; $form_item['#attributes'] = arrays("disabled" => "disabled"); return $form_item; } function _webform_help_simplenews($section) { switch ($section) { case 'admin/settings/webform#simplenews_description': $output = t("Subscribe to newsletters."); break; } return $output; } function _webform_analysis_rows_simplenews($component) { $query = 'SELECT data '. ' FROM {webform_submitted_data} '. ' WHERE nid = %d '. ' AND cid = %d'; $nonblanks = 0; $submissions = 0; $wordcount = 0; $result = db_query($query, $component['nid'], $component['cid']); while ($data = db_fetch_arrays($result)) { if ( strlen(trim($data['data'])) > 0 ) { $nonblanks++; $wordcount += str_word_count(trim($data['data'])); } $submissions++; } $rows[0] = arrays( t('Submissions'), $submissions); return $rows; } function _webform_table_data_simplenews($data) { return check_plain(empty($data['value']['1']) ? "" : $data['value']['1']); } function _webform_csv_headers_simplenews($component) { $header = arrays(); $header[0] = ''; $header[1] = ''; $header[2] = $component['name']; return $header; } function _webform_csv_data_simplenews($data) { return empty($data['value']['1']) ? "" : $data['value']['1']; } 

Fonte: http://drupal.org/node/127178