Mailbuild has the functionality to add custom fields, specifically for setting up sub-sections (segments) of the subscriber list. It would be nice to be able to add these fields to the block.

CommentFileSizeAuthor
#4 mailbuild.patch1.67 KBChris Gillis

Comments

dragonwize’s picture

I am currently adding many new features to the D6 port and have custom fields on my list to add functionality for. Obviously though there are many way that this could be done. Which also makes it very hard to fit every use case as well. Maybe this is a good place to brainstorm on that.

Questions:

What is your Mailbuild custom field use case?

How would you like to see this feature implemented?

Chris Gillis’s picture

I would like the ability to add fields to the block form using hook_form_alter, and having the soap submit them in the background. Maybe I could reference the custom field keys in a hidden field. I have made a start:

function mailbuild_block_view_form_submit($form_id, $form_values) {
  $params = array(
    'ApiKey' => variable_get('mailbuild_apikey', ''),
    'ListID' => $form_values['list']['id'],
    'Email' => $form_values['email'],
    'Name' => $form_values['name'],
  );
  if(!empty($form_values['custom_fields'])){
    $custom = explode(',', $form_values['custom_fields']);
    $customarray = array();
    foreach($custom as $fieldkey){
      if(is_array($form_values[$fieldkey])){
        $values = array_flip($form_values[$fieldkey]);
        unset($values[0]);
        if(!empty($values)){
          $customarray[] = array('Key' => $fieldkey, 'Value' => implode(',', $values));
        }
      } else if(!empty($form_values[$fieldkey])) {
        $customarray[] = array('Key' => $fieldkey, 'Value' => $form_values[$fieldkey]);
      }
    }
    if(!empty($customarray[0])){
      $params['CustomFields']['SubscriberCustomField'] = $customarray[0];//Only returns one field. Not sure how to match xml schema.
    }
  }
  if(!empty($params['CustomFields'])){
    drupal_set_message('<pre>'.print_r($params, TRUE).'</pre>');
    $result = mailbuild_soap_call('AddSubscriberWithCustomFields', $params);
  } else {
    $result = mailbuild_soap_call('AddSubscriber', $params);
  }
Chris Gillis’s picture

My params are now:

Array
(
    [ApiKey] => db1f472386b50478fce3967055a09418
    [ListID] => caa14ac90995257f9fe7edfa3810baf5
    [Email] => vo@visualobsession.com.au
    [Name] => harleys
    [CustomFields] => Array
        (
            [SubscriberCustomField] => Array
                (
                    [Key] => Position
                    [Value] => 13929
                )

        )

)

But I get the following: "There was an error subscribing to the list: NuSOAP library error"

I have tried key as: "Position", "fo-jltjd", and "mb.fo-jltjd" - nothing works.

Chris Gillis’s picture

Version: 5.x-1.0 » 5.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.67 KB

Finally done it.

With this patch in place, I can add my custom fields using form alter. I just need to make sure I submit a list (comma seperated) of their keys in a field called "custom_fields".

Please check and let me know what you think...

dragonwize’s picture

Thanks for putting this together. I plan to put out another version in the next 2 weeks. I will look this over and see if I can get it in.

jaydunford’s picture

Hi thekeyper,

I'd also like to be able to use the Mailbuild module with custom fields. I have patched the module with the patch you have provided but I'm a little unsure how to proceed. I have done some reading around Drupal's FormAPI but have not actually used it as yet, this seems like the ideal time to have a go.

I understand that you are adding the extra (custom) fields to the Mailbuild module's form using form_alter() but beyond that I am slightly lost. I assume that you are putting your code inside a custom module rather than in your theme's template.php ?

Any chance of posting the code I'd need to put into a custom module (if that is the way to do it) in order to work with your patch?

Cheers
senorJ

Chris Gillis’s picture

Hi senorJ!

You are on the right track. Create a new custom module and use form_alter. I have included the code I used below. (name of my custom module is 'bts')

function bts_form_alter($form_id, &$form){
  switch($form_id){
    case 'mailbuild_block_view_form':
      $form['Position'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Position'),
        '#default_value' => array(),
        '#options' => array('13929'=>t('Parent'), '13930'=>t('Teacher'), '13931'=>t('Librarian'), '13932'=>t('Principal')),
      );
      $form['custom_fields'] = array(
        '#type' => 'value',
        '#value' => 'Position',
      );
      $form['subscribe']['#weight'] = 1;
      break;
  }
}

The "custom_fields" element needs to have a comma-separated list of the keys of each of the extra fields you have added in. Let me know how you go.

-Chris

Chris Gillis’s picture

Status: Needs review » Closed (fixed)

This patch has been superseded by #303825: Major Upgrades.

Please direct all discussion there.