doukengzi3517 2016-10-18 10:58
浏览 57

使用PHP从动态创建的引导程序表单中检索值

I am working on a project where I allow the user to create enter one/many work experience details by dynamically adding form fields on click using a Bootstrap form. But am not sure of how to retrieve the values from these forms.

$(function()
    {
        $(document).on('click', '.btn-add', function(e)
        {
            e.preventDefault();

            var controlForm = $('.controls form:first'),
                currentEntry = $(this).parents('.entry:first'),
                newEntry = $(currentEntry.clone()).appendTo(controlForm);

            newEntry.find('input').val('');
            controlForm.find('.entry:not(:last) .btn-add')
                .removeClass('btn-add').addClass('btn-remove')
                .removeClass('btn-success').addClass('btn-danger')
                .html('<span class="glyphicon glyphicon-minus"></span>');
        }).on('click', '.btn-remove', function(e)
        {
            $(this).parents('.entry:first').remove();

            e.preventDefault();
            return false;
        });
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="controls">
                                        <li>
                                        <form role="form" autocomplete="off" method="post" action="<?php echo site_url('studentDashboardController/saveUserResumeDetails')?>">
                                            <div class="entry input-group col-xs-5">
                                                <input class="form-control" name="fields0[]" type="text" placeholder="Work Experience Title" />
                                                <input class="form-control" name="fields1[]" type="text" placeholder="Work Description" />
                                                <input class="col-md-6" name="fields21[]" type="text" placeholder="From(Year)" />
                                                <input class="col-md-6" name="fields22[]" type="text" placeholder="From(Month)" />
                                                <input class="col-md-6" name="fields31[]" type="text" placeholder="To(Year)" />
                                                <input class="col-md-6" name="fields32[]" type="text" placeholder="To(Month)" />
                                                <span class="input-group-btn">
                                                <button class="btn btn-success btn-add" type="button">
                                                    <span class="glyphicon glyphicon-plus"></span>
                                                </button>
                                                </span>
                                            </div>
                                        </form>
                                        </li>
                                        <br>
                                        <div class="form-group">
                                            <label class="col-md-4 control-label" for="submit"></label>
                                            <div class="col-md-4">
    <!--                                        <a href="--><?php //echo base_url("/index.php/studentDashboardController/saveUserResumeDetails"); ?><!--" >-->
                                                <button id="submit" name="submit" type="submit" class="btn btn-primary">Save Changes</button>
    <!--                                        </a>-->
                                            </div>
                                        </div>
                                    </div>

I'm working with the

  • CodeIgniter framework
  • PHP
  • MVC Architectureand

And the form above will basically be a part of my form and on submitting I call my controller studentDashboardController's saveUserResumeDetails method. From here, I'll be calling the userModel's saveUserResumeDetails method to store the user entered work experience detils into my studentprofile database table column.

The work experiences entered by the student will be stored in the following format inside the database table field.

work experience title - work description - 2015-08 - 2016-04, 
another work experience title - work description - 2016-03 - 2016-09, 
another work experience title - work description - 2014-10 - 2016-02, 

Database studentprofile Table

pic

Any suggestions in this regard will be highly appreciated.

</div>
  • 写回答

1条回答 默认 最新

  • doumowu7371 2016-10-18 11:34
    关注

    In your Controller, post all data to your model:

    $this->load->model('userModel');
    $user = new userModel();
    //print your post to debug, if necessary:
    //print_r($this->input->post());
    $user->saveUserResumeDetails($this->input->post());
    

    In your model, You've got an array of each field:

    public function saveUserResumeDetails($formData){
        foreach ($formData["fields0"] as $value) {
           echo "Filds0: $value<br />
    ";
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料