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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程