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 8329985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:58:29+00:00 2026-06-09T01:58:29+00:00

What I am trying to do is create a selectlist using the form API,

  • 0

What I am trying to do is create a selectlist using the form API, where a user can select rows and press a delete button that deletes the selected rows from the database and reloads the table with a conformation that those selected had been deleted. With my current code, when I hit the delete button I get this error:

Warning: Invalid argument supplied for foreach() in form_execute_handlers() (line 1431 of C:\xampp\htdocs\amaware\includes\form.inc).

Here is the code:

            /**
             * Implements hook_menu().
             */
            function smsfeed_menu() {
              $items = array();

              $items['admin/config/content/smsfeed'] = array(
                'title' => 'SMS Messages and Newsletters',
                'description' => 'Edit the Setting for the SMS Feed and Newsletter',
                'page callback' => 'drupal_get_form',
                'page arguments' => array('smsfeed_form'),
                'access arguments' => array('access administration pages'),
                'type' => MENU_NORMAL_ITEM,
                );

              $items['admin/config/content/smsfeed/settings'] = array(
                'title' => 'Settings',
                'type' => MENU_DEFAULT_LOCAL_TASK,
                    'weight' => 1,
                );  

              $items['admin/config/content/smsfeed/newsletter'] = array(
                'title' => 'Newsletter',
                'page callback' => 'drupal_get_form',
                    'page arguments' => array('newsletter_table_form'),
                'access arguments' => array('access administration pages'),
                'type' => MENU_LOCAL_TASK,
                    'weigth' => 2,
                    );

              $items['admin/config/content/smsfeed/feed'] = array(
                'title' => 'SMS Feed',
                'page callback' => 'drupal_get_form',
                'page arguments' => array('feed_form'),
                'access arguments' => array('access administration pages'),
                'type' => MENU_LOCAL_TASK,
                    'weight' => 3,
                    );

              $items['admin/config/content/smsfeed/questions'] = array(
                'title' => 'Questions',
                'page callback' => 'drupal_get_form',
                'page arguments' => array('questions_form'),
                'access arguments' => array('access administration pages'),
                'type' => MENU_LOCAL_TASK,
                    'weigth' => 4,
                    );

              return $items;
            }

            /**
             * Page callback: SMS Settings
             *
             * @see smsfeed_menu()
             */
            function smsfeed_form($form, &$form_state) {
              $form['response_time'] = array(
                '#type' => 'textfield',
                '#title' => t('Response Time (In Days)'),
                '#default_value' => variable_get('response_time', 3),
                '#size' => 2,
                '#maxlength' => 2,
                '#description' => t('The response time, in days, that users should expect.'),
              );

                $form['feed_keyword'] = array(
                  '#type' => 'textfield',
                '#title' => t('Feed Keyword'),
                '#default_value' => variable_get('feed_keyword', 'FEED'),
                '#size' => 10,
                '#maxlength' => 10,
                '#description' => t('The keyword users should text to have their message moderated and added to the website feed.'),
              );

                $form['join_keyword'] = array(
                  '#type' => 'textfield',
                '#title' => t('Join Keyword'),
                '#default_value' => variable_get('join_keyword', 'JOIN'),
                '#size' => 10,
                '#maxlength' => 10,
                '#description' => t('The keyword users should text to be added to the newsletter list.'),
              );

                $form['quit_keyword'] = array(
                  '#type' => 'textfield',
                '#title' => t('Quite Keyword'),
                '#default_value' => variable_get('quit_keyword', 'QUIT'),
                '#size' => 10,
                '#maxlength' => 10,
                '#description' => t('The keyword users should text to be removed from the newsletter list.'),
              );    

              return system_settings_form($form);
            }

            /**
             * Page Callback Newsletter
             */

            function newsletter_table_form($form, $form_state) {
                $rows = array();
                $header = array(t('User Name'), t('User Number'), t('User E-mail'),);

                $query = db_select('sms_newsletter');
                $query->fields('sms_newsletter', array('name', 'number', 'email',))
                    ->orderBy('name', 'ASC');
                $results = $query->execute();

                foreach ($results as $line) {
                    $rows[] = array(
                        $line->name,
                        $line->number,
                        $line->email,
                    );
                }

              $form['table'] = array(
                '#type' => 'tableselect',
                '#header' => $header,
                '#options' => $rows,
                '#empty' => t('No users found'),
              );

              $form['delete'] = array(
                '#type' => 'submit',
                '#value' => t('Delect Selected'),
                    '#submit' => 'newsletter_table_form_delete'
              );
              return $form;
            }

            function newsletter_table_form_delete ($form, &$form_state) {
                foreach ($form_state['values']['collections'] as $key => $value) {
                    if ($value) {
                            $delete = db_delete('sms_newsletter')
                            -> execute();
                    }
                }   
            }

Any help is deeply appreciated.

EDIT:
I’ve edited my news_letter_table_form to read:

function newsletter_table_form_delete ($form, $form_state) {
    foreach (($form_state['values']['table']) as $rows) {
            //$delete = db_delete('sms_newsletter')
            //-> execute();
            drupal_set_message ('' . $rows  . '');
    //drupal_set_message ('' . $form_state['values']['table']       . '');
    }
}

And the new output leaves me puzzled as to how I’d identify selected rows, and delete them from the database. Using the above newsletter_table_form_delete I get the following output:

  1. If I select the top row nothing happens
  2. If I select the second row the output is 1
  3. If I select the third row the output is 2 and so on
  4. If I select multiple rows the output is an unordered html list of the selected rows.

I’m curious now how I could take what I have now and change it so I can delete selected rows from the database.

Thanks again!

  • 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-06-09T01:58:32+00:00Added an answer on June 9, 2026 at 1:58 am

    Try changing

      $form['delete'] = array(
        '#type' => 'submit',
        '#value' => t('Delect Selected'),
            '#submit' => 'newsletter_table_form_delete'
      );
    

    to

      $form['delete'] = array(
        '#type' => 'submit',
        '#value' => t('Delect Selected'),
            '#submit' => array('newsletter_table_form_delete') // <-- make this an array
      );
    

    Based on the additional info added in your question edit, I noticed that your tableselect is built without specifying array keys like:

    foreach ($results as $line) {
        $rows[] = array(  // <-- No array keys specified here 
            $line->name,
            $line->number,
            $line->email,
        );
    }
    

    Since there were no keys specified, the default by PHP is a 0-based index. That is why you are getting no results for the top row, 1 for the second row, and so on.

    See the documentation for the tableselect element for an example.

    I don’t know what your database table structure looks like but you will probably need to query the Primary Key for the table and include it as array keys to your $rows array. That way, when you process the data in your delete function, you have the Primary Key of the row you want to delete and delete it.

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

Sidebar

Related Questions

I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
ok so I am trying to dynamically create a select list using javascript, basically
I am trying to create a search function that allows the user to search
I am trying to create a form in ASP.NET MVC2 RC 2 that is
I am trying to create a select list starting from the current date of
I am trying to populate a select list with time. I want to create
Ok so I am trying create a login script, here I am using PHP5
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
Trying to create a macro which can be used for print debug messages when
I'm trying to produce a dropdownlist for GetAllRoles using the role provider. I can

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.