Closed (works as designed)
Project:
Simplenews
Version:
7.x-1.0-beta1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Feb 2012 at 19:13 UTC
Updated:
21 Feb 2012 at 18:26 UTC
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
Comment #0.0
Saoirse1916 commentedGot rid of extraneous comments
Comment #1
Saoirse1916 commentedIt looks like a similar change needs to be done to the simplenews_block_form_submit function:
Comment #2
berdirI 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.
Comment #3
Saoirse1916 commentedSure 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!
Comment #4
selvaraj123 commentedIn mail i can not see header image and footer image.only url able to see.
any suggestion for this simple new module
Comment #4.0
selvaraj123 commentedRemoved extraneous debugging code.