duande1985 2012-06-05 14:25
浏览 52

在CodeIgniter中处理大量半相关表单

I have a 20 page document with 20 forms in it. It's organized into sections.

Section 1:
 1.1 - Form 1
 1.2 - Form 2
 1.3 - Form 3
Section 2:
 2.1 - Form 1

...etc...

I have a controller setup that looks something like this (for now):

class Section extends CI_Controller {
    public function index($section_id) {
        $this->section_model->_require_valid_section($section_id);

        $data['view'] = "section/index";
        $this->load->view('app/template', $data);
    }
}

I need to build views for these 20 forms. Each form has different data. One might have "Name, Email, Phone" while the next might have "Person Name, Facility Name, Title" and they aren't related. I think it is probably silly to have a table for each form (more forms could come at any time), so I could do a table like this:

Section | Key     | Value
-------------------------
1.1      name       Randolph
1.1      phone      1111111111
2.1      person     Junior
2.1      title      Playa 

I'd really like to know how I could set up my controller to handle and route requests for these forms.

Would it be ideal to just create functions for each one?

public function form_1_1() {
   $this->section_model->save_1_1();
}
public function form_1_2() {
   $this->section_model->save_1_2();
}

index() could route the requests via call_user_func() but I don't know if thats the right way to do it.

  • 写回答

2条回答 默认 最新

  • douaoj0994 2012-06-05 17:33
    关注

    you could always just put a hidden input in each form and then inside your controller function act on what the value of the hidden field is.

    Add to views in each form:

    <input type="hidden" name="form_name" value="form_1" />
    

    Add to controller:

    $form_submitted = $this->input->post('form_name');
    

    Then just use a switch or if to handle the data based on the $form_submitted variable.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向