我有四个文本框,当你点击添加一个按钮时,它会添加另一组文本框。我的问题是如何将json数据传递给动作表单。这是我的代码:
$("#test").click(function(){
var array = $('.experience').map(function() {
var obj = {};
$(this).next().addBack().find('input:text').each(function() {
obj[this.id] = this.value;
});
return obj;
}).get();
$('#json').text(JSON.stringify(array, null, 2));
});
和我的表单行动
<form action="<?php echo base_url().'resume/update'?>" method="post" id="send_form">
<!-- Experience Start -->
<div class="row">
<div class="col-sm-12">
<p> </p>
<h2>Experience</h2>
</div>
</div>
<div class="row experience">
<div class="col-sm-6">
<div class="form-group">
<label for="resume-employer">Employer</label>
<input type="text" class="form-control" name="resumeEmployer" id="resume-employer" value="<?php echo set_value('resumeEmployer'); ?>" id="resume-employer" placeholder="Company name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="resume-experience-dates">Start/End Date</label>
<input type="text" class="form-control" name="resumeExperienceDates" name="<?php echo set_value('resumeExperienceDates'); ?>" id="resume-experience-dates" placeholder="e.g. April 2010 - June 2013">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="resume-job-title">Job Title</label>
<input type="text" class="form-control" name="resumeJobTitle" id="resume-job-title" value="<?php echo set_value('resumeJobTitle'); ?>" placeholder="e.g. Web Designer">
</div>
</div>
<div class="col-sm-6">
<div class="form-group" id="resume-responsibilities-group">
<label for="resume-responsibilities">Responsibilities (Optional)</label>
<input type="text" class="form-control" name="resumeResponsibilities" id="resume-responsibilities" value="<?php echo set_value('resumeResponsibilities');?>" placeholder="e.g. Developing new websites">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<hr class="dashed">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<p><a id="add-experience">+ Add Experience</a></p>
<hr>
</div>
</div>
<!-- Experience Start -->
<div class="row text-center">
<div class="col-sm-12">
<p> </p>
<input type="submit" id="test" class="btn btn-primary btn-lg" value="Submit" />
</div>
</div>
</form>
我添加了一个id =&#34; test&#34;在输入类型=&#34;提交按钮
非常感谢任何帮助。 TIA
答案 0 :(得分:0)
在参考链接中使用json_encode
和json_decode
功能示例,
json_encode($arr);
var_dump(json_decode($json));
http://php.net/manual/en/function.json-encode.php
var_dump(json_decode($json, true));