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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:08:06+00:00 2026-06-04T08:08:06+00:00

I have a populated CodeIgniter form_multiselect. With values in it Code for that is

  • 0

I have a populated CodeIgniter form_multiselect. With values in it

Code for that is as follows:

<select multiple="multiple" name="EMPLOYEES_id[]">
 <option value="8">Employee 8</option>
 <option value="1">Employee 1</option>
 <option value="12">Employee 12</option>
</select>

This runs on a system where you can send messages to multiple users. So what I’d like to do is say the user selects value 1 and value 8. I would like to run two inserts with the same data in but the only difference is the EMPLOYEES_id field in the database is different each time.

My Model is as follows:

function create()
{
    $this->template->set('title', 'Create Message');


    // Validate the form input
    $this->form_validation->set_error_delimiters('<span class="help-inline">', '</span>');
    $this->form_validation->set_rules('MESSAGE_summary', 'Message Summary', 'trim|required|xss_clean');
    $this->form_validation->set_rules('MESSAGE_body', 'Message Body', 'trim|required|xss_clean');


    if($this->form_validation->run() == FALSE)
    {

        // Get all users in same company as logged in user
        $comapny_contacts = $this->Employees_model->read_company_contacts($this->viewinguser->BUSINESSES_id);
        $comapny_contacts = $comapny_contacts->result();

        foreach($comapny_contacts as $contacts)
        {
            $comapny_contacts_options[$contacts->EMPLOYEES_id] = $contacts->EMPLOYEES_firstname . ' ' . $contacts->EMPLOYEES_surname;
        }

        $this->template->set('comapny_contacts_options', $comapny_contacts_options);


        // form has not been run or there are validation errors
        $this->template->build('messages/create');
    }
    else
    {

        /*
         * Lets create the new message in the database
         */
        $insert_data = new stdClass();
        $insert_data->MESSAGES_summary = $this->input->post('MESSAGE_summary');
        $insert_data->MESSAGES_body = $this->input->post('MESSAGE_body');
        $insert_data->MESSAGES_level = $this->input->post('MESSAGES_level');
        $insert_data->MESSAGES_type = $this->input->post('MESSAGES_type');
        $insert_data->MESSAGES_createdby = $this->activeuser->EMPLOYEES_id;
        //$insert_data->EMPLOYEES_id = $this->input->post('EMPLOYEES_id');
        foreach($this->input->post('EMPLOYEES_id') as $employee_id)
        {
            $insert_data->EMPLOYEES_id = $employee_id;

            // Save to new message in the database
            $this->Messages_model->create($insert_data);
        }

        /*
         * Now lets save a notification email in the database to be sent to the user
        */
        $notification_body = '
        <p>A new message has been added for you  by ' . $this->session->userdata('activeuser')->EMPLOYEES_firstname . '<br />
        ------------------------------</p>
        <p><strong>Summary:</strong> ' . $this->input->post('MESSAGE_summary') . '</p>
        <p>------------------------------<br />
        <a class="btn" href="' . base_url('messages') . '">Click to view full messages</a>';

        // Get the info for the user who the notification is for
        $notify_user_info = $this->Employees_model->read_single_switch($this->input->post('EMPLOYEES_id'));
        $notify_user_info = $notify_user_info->result();

        // Set all the data
        $insert_data = new stdClass();
        $insert_data->NOTIFICATIONS_toname = $notify_user_info[0]->EMPLOYEES_firstname . ' ' . $notify_user_info[0]->EMPLOYEES_surname;
        $insert_data->NOTIFICATIONS_toemail = $notify_user_info[0]->EMPLOYEES_email;
        $insert_data->NOTIFICATIONS_subject = 'A new message has been added for you';
        $insert_data->NOTIFICATIONS_htmlbody = $notification_body;
        //$insert_data->EMPLOYEES_id = $this->input->post('EMPLOYEES_id');
        foreach($this->input->post('EMPLOYEES_id') as $employee_id)
        {
            $insert_data->EMPLOYEES_id = $employee_id;

            // Save to new notification to the database
            $this->Notifications_model->create($insert_data);
        }

        // show user confirmation
        $this->session->set_flashdata('success_message', 'New message created successfully.');
        redirect('messages');
    }
  • 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-04T08:08:08+00:00Added an answer on June 4, 2026 at 8:08 am

    The easiest way would be to set up all the common parameters and then insert data on each foreach iteration of the $this->input->post('EMPLOYEES_id').

     foreach($this->input->post('EMPLOYEES_id') as $eid){
          // insert data using $uid as the employer id here
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write the key and value pair that i have populated in
I have populated an array with a few html image tags that I have
In a controller, I have populated a map that has a string as key
I have a DataTable populated with values from a database. I have another datatable
I have a sparsely populated vector that I populated via hashing, so elements are
I have a simple form in codeigniter that I wish to use for the
i have populated gridview from SaleDAL class, assuming following is the code, Please ignore
I have created a Spinner and have populated it with values for my app
i have a datagridview that i have populated programmatically and i was wondering how
I have a configuration bean that has a list of allowed values: @Component public

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.