php – CodeIgniter form_multiselect
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – CodeIgniter form_multiselect,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3681字,纯文字阅读大概需要6分钟。
内容图文
![php – CodeIgniter form_multiselect](/upload/InfoBanner/zyjiaocheng/777/c2f4f1abcd5b4f4088b5728c15b3cc20.jpg)
我有一个填充的CodeIgniter form_multiselect.有价值观
代码如下:
<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>
这在您可以向多个用户发送消息的系统上运行.所以我想要做的是说用户选择值1和值8.我想运行两个具有相同数据的插入,但唯一的区别是数据库中的EMPLOYEES_id字段每次都不同.
我的模型如下:
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');
}
解决方法:
最简单的方法是设置所有公共参数,然后在$this-> input-> post(‘EMPLOYEES_id’)的每个foreach迭代中插入数据.
foreach($this->input->post('EMPLOYEES_id') as $eid){
// insert data using $uid as the employer id here
}
内容总结
以上是互联网集市为您收集整理的php – CodeIgniter form_multiselect全部内容,希望文章能够帮你解决php – CodeIgniter form_multiselect所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。