效果图:
前端页面:
<div class="contact-right"> <h2>合作意向表/ <span>COOPERATION INTENTION FORM</span></h2> <form id="contact-form" action="/message2/add" method="POST" role="form"> <div class="form-group"> <input type="text" class="form-control" id="company" placeholder="公司名称" name="company" required> </div> <div class="form-group"> <input type="text" class="form-name" id="name" placeholder="姓名" name="name" required> <input type="tel" class="form-iphone" id="tel" placeholder="电话" name="tel" required> </div> <div class="contact-hope"> <h2>您希望我们为您提供什么服务?</h2> </div> <div class="duoxuan"> <div class="check"> <input type="checkbox" name="service[]" value="APP开发及解决方案"> <p>APP开发及解决方案</p> </div> <div class="check"> <input type="checkbox" name="service[]" value="网站建设与维护"> <p>网站建设与维护</p> </div> <div class="check"> <input type="checkbox" name="service[]" value="微信小程序开发"> <p>微信小程序开发</p> </div> <div class="check"> <input type="checkbox" name="service[]" value="企业设计包年服务"> <p>企业设计包年服务</p> </div> <div class="check"> <input type="checkbox" name="service[]" value="品牌策划VI视觉"> <p>品牌策划VI视觉</p> </div> <div class="check"> <input type="checkbox" name="service[]" value="系统开发"> <p>系统开发 </p> </div> </div> <div id="tipscont" style="height:25px; color:red;"></div> <div class="sumbit"> <button type="submit">提交需求</button> </div> </form> </div>
后台处理:(表单中action跳转的后台处理
/message2/add
)
public function add() { $data = []; $data['company'] = I('company'); $data['name'] = I('name'); $data['tel'] = I('tel'); // 服务内容 $data['services'] = ""; $service_list = I('service'); if ($service_list) { $data['services'] = implode(', ', $service_list); } $data['ip'] = get_client_ip(); $cont = "公司名称:{$_POST['company']} \n\r"; $cont .= "姓名:{$_POST['name']} \n\r"; $cont .= "电话:{$_POST['tel']} \n\r"; $cont .= "我们的服务:{$data['services']} \n\r"; $res = think_send_mail('[email protected]', '您有新消息', '您有新消息', $cont); // echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); $model = M('Message2'); if ($model->add($data) === false) { $err_msg = $model->getError(); $err_msg = $err_msg ? $err_msg : '未知错误'; $res = [ 'ok' => false, 'msg' => $err_msg ]; } else { $res = [ 'ok' => true, 'msg' => '留言已经提交到后台,请耐心等待' ]; } echo json_encode($res, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); }
数据表的设计:
CREATE TABLE `o_message2` ( `id` int(11) NOT NULL AUTO_INCREMENT, `company` varchar(255) DEFAULT NULL COMMENT '公司', `name` varchar(255) DEFAULT NULL COMMENT '姓名', `tel` varchar(255) DEFAULT NULL COMMENT '电话', `services` varchar(1024) DEFAULT NULL COMMENT '服务', `created_at` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '日期', `ip` varchar(255) DEFAULT NULL COMMENT 'IP地址', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
最后,后台效果:
标签:COMMENT,cont,--,留言,数据库,DEFAULT,msg,NULL,data From: https://www.cnblogs.com/gaoyusui/p/16831899.html