我有个案子要解决。我学习ci框架已经快一个月了。我想做的是,我想把输入字段中的值以一种我动态添加到mysql表中的形式存储起来,但我不知道怎么做。我已经有了视图的html+javascript脚本。
html脚本
<div class="input_fields_wrap">
<button class="add_field_button">Add More Fields</button>
<div>
<input type="text" name="mytext[]" placeholder="Account Title">
<input type="text" name="mytext2[]" placeholder="Description">
<input type="text" name="mytext3[]" placeholder="Credit">
<input type="text" name="mytext4[]" placeholder="Debit">
</div>
</div>
javascript脚本
<script type="text/javascript">
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div><input type="text" name="mytext[]" placeholder="Account Title"><input type="text" name="mytext2[]" placeholder="Description"><input type="text" name="mytext3[]" placeholder="Credit"><input type="text" name="mytext4[]" placeholder="Debit"><a href="#" class="remove_field">Remove</a></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
</script>
有没有人能帮我把值从控制器传给数据库?很抱歉,我是新来的ci框架,所以请原谅我问这样的问题。
1条答案
按热度按时间r8xiu3jd1#
使用
这将创建一个表单,并使用jquery以serializearray()的形式获取数据,然后使用ajax或formsubmit将数据传递给控制器
在你的控制器里,