I've been going through the forums and have tried just about every suggestion out there on how to theme the Simplenews block. Specifically, I'd like to change the value of the submit button and change the radios to a hidden field that defaults to "Subscribe".

I've tried mythemename_preprocess_simplenews_block, simplenews_block_form_alter, simplenews_block_1_form_alter, simplenews_block_simplenews-block-form-1_alter... none of them appear to have any affect at all... How can I alter the simplenews form in Drupal 6?

function mytheme_preprocess_simplenews_block(&$variables) {
  global $user;
  $form = array();

  if ($user->uid) {
    if (simplenews_user_is_subscribed($user->mail, $tid)) {
      $submit_text = t('Unsubscribe');
      $form['action'] = array('#type' => 'value', '#value' => 'unsubscribe');
    }
    else {
      $submit_text = t('Subscribe');
      $form['action'] = array('#type' => 'value', '#value' => 'subscribe');
    }
    $form['display_mail'] = array(
      '#type' => 'item',
      '#title' => t('User'),
      '#value' => check_plain($user->name),
    );
    $form['mail'] = array('#type' => 'value', '#value' => $user->mail);
  }
  else {
    $form['mail'] = array(
      '#type' => 'textfield',
      '#title' => t('Email'),
      '#size' => 20,
      '#maxlength' => 128,
      '#required' => TRUE,
    );
    $form['action'] = array(
      '#type' => 'hidden',
      '#value' => 'subscribe',
    );
  }

  // All block forms use the same validate and submit function.
  // #tid carries the tid for processing of the right newsletter issue term.
  $form['#tid'] = $tid;
  $form['#validate'][] = 'simplenews_block_form_validate';
  $form['#submit'][] = 'simplenews_block_form_submit';
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => isset($submit_text) ? $submit_text : t('Subscribe')
  );
  return $form;
}

Comments

chipway’s picture

You may try something like this :

1) copy the function from simplenews.module
function template_preprocess_simplenews_block(&$variables) {
....
variables defs
....
}
in your theme template,

2) then call it
function mytheme_preprocess_simplenews_block(&$variables) { }

3)then change some references to your own mysimplenews_customize.module, in which you put your custom functions, ...

Hope this helps.

Drupal Consultancy, Development & Training, Lyon, Paris, France, Suisse. https://chipway.com.

pasive’s picture

I made a nod with full process description.
I hope that will help.

http://drupal.org/node/859656

vindesh’s picture

Form theme registry in template.php file

function bartik_theme() {
  return array(
    'simplenews_block_form_1' => array(      
      'render element' => 'form',
      'template' => 'simplenews-block-form',
      'path' => drupal_get_path('theme', 'bartik').'/templates',
    ),			
  );
} 

function bartik_preprocess_simplenews_block_form_1(&$variables) {
  	// Shorten the form variable name for easier access.
  	$form = $variables['form'];
  	unset($form['mail']['#title']);
  	$form['mail']['#id'] = 'exampleInputEmail1';
  	$form['mail']['#attributes'] = array('class' => array('form-control'));
  	$form['mail']['#attributes']['placeholder'] = t('Enter Your Email');
  	$form['submit']['#value'] = t('Sign Up');
  	$form['submit']['#attributes'] = array('class' => array('licence_btn') );
  	$variables['heading'] = t('Sign up for our Newsletter to receive updates that will help you!'); 
 	// Create variables for individual elements.
	$variables['mail'] = render($form['mail']);
	$variables['submit'] = render($form['submit']);	 
	// Be sure to print the remaining rendered form items.
	$variables['children'] = drupal_render_children($form);
}

create simplenews-block-form.tpl.php file and add in theme directory "bartik/templates/simplenews-block-form.tpl.php"

Place your own html and put the variable, as show below-

filename: simplenews-block-form.tpl.php

<div class="contact_form news-form">
  <div class="container">
    <div class="row">
      <div class="col-sm-12 text-center">
        <h2> <span class="icons-a"><img src="<?php print drupal_get_path('theme', 'bartik');?>/img/news-letter-icon.png" alt="icon"></span> 
        <?php print t("Newsletter");?></h2>
        <p><?php print $heading;?> </p>
      </div>
    </div>
    <div class="row contact_field">
      <div class="sign-up-row clearfix">
        <div class="snp-1">
          <?php print $mail; ?>
        </div>
        <div class="snp-2">
          <?php print $submit; ?>
        </div>
      </div>
    </div>
  </div>
</div>
<?php print $children; ?>

Its done!
Its very simple way to implement simplenews signup block with own design.....@Vindesh