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
Any suggestions in this regard will be highly appreciated.
</div>