I've got a Simplenews block set up to allow anonymous users to submit their emails to join the newseletter. However, the validation always responds with the above error, even if the email address is valid. What I found is that the problem is tied to the following code:

<?php
/*
 * FAPI BLOCK subscription form_validate.
 */
function simplenews_block_form_validate($form, &$form_state) {
  if (!valid_email_address($form_state['values']['mail'])) {
    form_set_error('mail', t("The e-mail address you supplied is not valid."));
  }
}
?>

The issue is that $form_state['values']['mail'] always holds the value "Email Address", rather than the submitted value itself. What it should reference is $form_state['input']['mail'] and for uniformity with the other validation routines executed later in the file, I rewrote it like so:

<?php
function simplenews_block_form_validate($form, &$form_state) {
	$valid_email = valid_email_address($form_state['input']['mail']);
	if (!$valid_email) {
    form_set_error('mail', t("The e-mail address you supplied is not valid."));
  }
}
?>

Comments

Saoirse1916’s picture

Issue summary: View changes

Got rid of extraneous comments

Saoirse1916’s picture

It looks like a similar change needs to be done to the simplenews_block_form_submit function:

<?php
switch ($form_state['values']['action']) {
    case 'subscribe':
      simplenews_subscribe_user($form_state['input']['mail'], $tid, $confirm, 'website');
?>
berdir’s picture

Status: Active » Postponed (maintainer needs more info)

I have no idea why that would be so. Using $form_state['input'] is *wrong*, it contains the unvalidated, raw values from $_POST. That should *never* be used.

It certainly isn't like that in the tests, I've never seen this as a problem with manul testing nor has any of the 8k users reported this before. In fact, there is no "Email Address" string *anywhere* in this module, "Email" has been renamed to "E-mail" to follow the UX standards defined in Drupal 7. There is also no default value on the subscribe block anymore (there is in 6.x-1.x I think).

Make sure this is not caused by some broken hook_form_alter() code or another contrib module on your site. Try to reproduce it on a clean Drupal 7 site with just Simplenews installed, you might also want to try another browser.

Saoirse1916’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Sure enough -- there was another module that was forcing the value of input to default text that would be cleared by jQuery. However, it appears that the jQuery was not functioning properly so I've changed it to putting a title in place and clearing on that, which allowed me to reset Simplenews to $form_state['values']['mail'].

Thanks for the tip!

selvaraj123’s picture

In mail i can not see header image and footer image.only url able to see.

any suggestion for this simple new module

selvaraj123’s picture

Issue summary: View changes

Removed extraneous debugging code.