Hi,
I am currently trying to add and save a new (name) field to simplenews subscription block. At the time being, simplenews subscription block contains only an email field.
http://i51.tinypic.com/2lw1ydl.png (This is the block that I willing to add)
I have created a module (modify_simplenews) so I can alter the form and save the field in the database .
function modify_simplenews_form_alter(&$form, &$form_state, $form_id) {
switch($form_id) {
case 'simplenews_block_form_1':// <-- 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'][] = 'modify_simplenews_block_form_submit';
break;
}
}
function modify_simplenews_block_form_submit($form, &$form_state) {
if ($form['#id'] == 1) {
$name = $form_state['values']['name'];
// Do something here to store the name in the database
// ...
// ...
}
}
However, I don't know what should I do to save the name field in the database. The subscriber table in simplenews only contains an email field, should I add a name field to the database structure of the Subscriber table? What is the code that can be used to store the name variable in the database ?
Thanks!
Comments
Comment #1
miro_dietikerUse this module for that. It does what you're trying to.
http://drupal.org/project/simplenews_realname
However, for Drupal 7 it is not yet existing. But you could help porting it... At least it's a better start than your code only.
Comment #3
heyehren commentedThe simplenews realname module doesn't work properly at the moment. It throws errors when trying to add the name field: http://drupal.org/node/1912712
Comment #4
emilorol commentedHi,
I have spend a big part of todays day fixing the issues mention on the linked post as I need the functionality of the module in a current project. I plan to later on submit a patch that will wrap all the changes in a single file. Meanwhile all the fixes can be apply manually. Scroll down in the page http://drupal.org/node/1912712 to the fixes.
Comment #5
yuseferi commentedI achieve it by myself idea, you can do something like me
in custom form_alter
It cause show the email box even user is logged in , I hope this help others that like something like this, email box for logged in user in simplenews subscription form