I am trying to add Additional Processing code through editing a webform. The code is:

<?php simplenews_subscribe_user($form['email'], '1', false); ?>

The name of the field I want to retrieve is definitely 'email' and submitting saves the webform fine. But, when I go to admin/content/simplenews/users - although there is a new subscriber, his/her email field is empty.

Do I have a mistake somewhere?

Thanks!

Comments

zvischutz’s picture

You can use
simplenews_subscribe_user($form['submitted']['email']['#value'],'1',false);

where submitted is the name of the form of the webform , email is the field key of the form component that contains the email. You can see those details in the source of the webform page created.

See the Forms API (http://api.drupal.org/api/file/developer/topics/forms_api.html) for more details how the form fields are treated.

Regards
Zvi

amir simantov’s picture

Hi Zvi and thanks for the code and much info!

I have tried the exact code and it still does not bring the email address - same phenomenon as described above.

The relevant html source code is:

<div class="form-item" id="edit-submitted---------frame-email-wrapper"> 
 <label for="edit-submitted---------frame-email">כתובת אימייל: <span class="form-required" title="חובה למלא שדה זה.">*</span></label> 
 <input type="text" maxlength="128" name="submitted[________frame][email]" id="edit-submitted---------frame-email" size="60" value="" class="form-text required" /> 
</div> 

Any ideas?

Thanks!

jjkiesch’s picture

i got it working with

simplenews_subscribe_user($form_values['submitted_tree']['email'], '11', FALSE); 
drupal@guusvandewal.nl’s picture

Hi, thank you all for pointing me into the right direction, I've added some code to add people to the newsletter only if they agree so. (with a checkbox field)

  if ($form_values['submitted_tree']['schrijf_in'] == 'ja') {
simplenews_subscribe_user($form_values['submitted_tree']['uw_email'], '1', FALSE);
}

schrijf_in = the fieldname of the checkbox field , value is either 'ja' (yes) or 'nee' (no), in which case it does nothing
uw_email = the fieldname of email
1 is the $tid of my newsletter, but it can change, I'm not sure how to always correctly find it.

Gus