Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6572235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:58:49+00:00 2026-05-25T14:58:49+00:00

Anyone able to offer some ideas on this? Basically the module I’m building has

  • 0

Anyone able to offer some ideas on this? Basically the module I’m building has a form (as per function_email_solicitors_compose), and on submission we obviously route to form_emails_solicitors_compose_submit. Here I define a batch in $batch, and batch_set the aforementioned batch. The drupal documentation says I don’t need to run batch_process() if it’s called from within a form_submit, which this is, but I’ve tried with and without. All tests have shown that it gets as far as defining the batch but never goes any further than that. email_solicitors_batch_iteration never runs. Any ideas?

As an additional bit of info, batch_get then returns the following:

Array
(
    [sets] => Array
        (
            [0] => Array
                (
                    [sandbox] => Array
                        (
                        )

                    [results] => Array
                        (
                        )

                    [success] => 
                    [title] => Emailing.
                    [operations] => Array
                        (
                            [0] => Array
                                (
                                    [0] =>

email_solicitors_batch_iteration
[1] => Array
(
[0] =>
[1] =>
)

                                )

                        )

                    [finished] => my_finished_callback
                    [init_message] => Initializing.<br/>&nbsp;
                    [progress_message] => Remaining

@remaining of @total.
[error_message] => An error has
occurred.
[total] => 1
)

        )

)

The code:

function email_solicitors_compose(){
    $form['email_solicitors_subject'] = array(
        '#type' => 'textfield',
        '#title' => t('Subject'),
        '#description' => t('Enter the subject of your email'),
        '#default_value' => 'Subject',
        '#size' => 30
    );
    $form['email_solicitors_message'] = array(
        '#type' => 'textarea',
        '#title' => t('Message'),
        '#description' => t('Write your message here. <strong>Please note that we will automatically add "Dear #name", which will be personalised to the solicitor.</strong>'),
        '#default_value' => '',
    );
    $form['email_solicitors_submit'] = array(
        '#type' => 'submit',
        '#title' => t('Submit'),
        '#description' => t('Sumbit this form.'),
        '#default_value' => 'Submit',
    );
    return $form;
}//function email_solicitors_compose


function email_solicitors_compose_submit($form_state)
{
    $batch = array(
        'title' => t('Sending emails to solicitors'),
        'operations' => array(
            array('email_solicitors_batch_iteration', array())
        ), 
        'finished' => 'email_solicitors_batch_finished', //run this when we're finished
        'init_message' => t('Preparing to send emails'), //initialisation message
        'progress_message' => t('Sent @current out of @total messages.'),
        'error_message' => t('Sorry, something went wrong when sending emails.'),
    );// create batch array
    $info=print_r($batch,TRUE);
    drupal_set_message($info);
    batch_set($batch);
    batch_process();
}//function email_solicitors_compose_submit


function email_solicitors_batch_iteration(&$context)
{
    // Initialize sandbox the first time through.
    if (!isset($context['sandbox']['progress'])) {
        $context['sandbox']['progress'] = 0;
        $context['sandbox']['current_user_id'] = 0;
        $context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT field_solicitor_email_value) FROM content_type_solicitor'));
    }
    $comment="On item ".$context['sandbox']['progress'];
    drupal_set_message ($comment);
}//function email_solicitors_batch_iteration

function email_solicitors_batch_finished (&$context)
{
    die ('woohoo we finished');
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:58:50+00:00Added an answer on May 25, 2026 at 2:58 pm

    As an addition to the answer Clive has given, you could consider adding the “file” parameter to the batch-array. This will tell the API where the function is located.

    Example:

       $batch = array(
            'title' => t('Sending emails to solicitors'),
            'operations' => array(
                array('email_solicitors_batch_iteration', array())
            ), 
            'finished' => 'email_solicitors_batch_finished', //run this when we're finished
            'init_message' => t('Preparing to send emails'), //initialisation message
            'progress_message' => t('Sent @current out of @total messages.'),
            'error_message' => t('Sorry, something went wrong when sending emails.'),
            'file' => drupal_get_path('module', '<module_name>').'/path_to_include_file.inc',
        );
    

    It worked for me 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone suggest a CMS able to offer the following features: Free/open source Support
Has anyone been able to get an NHibernate-based project up and running on a
Has anyone been able to get xinc to run correctly under OpenBSD's chrooted default
Has anyone been able to get a variable record length text file (CSV) into
Has anyone been able to successfully unit test methods that are, by necessity, coupled
Has anyone been able to create Container-Specific Master Pages for Safari or Chrome? I
Has anyone been able to succesfully use the IE CSS hack #IEroot? I stumbled
Has anyone been able to implement the JQuery grid plugin, jqGrid? I'm trying to
Has anyone been able to customize jQGrid? While I'd like something easy I can
Basically I'm wondering if anyone has any tips for ensuring your code is well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.