I need to create a form to create assessments, with lots of variable questions. For this I created a form that adds questions, as requested;
The problem is to save on%% of this variety of issues. To be clearer, follow the Code;
<div class="box">
<div class="box-header">
<ul class="nav nav-tabs nav-tabs-left">
<li class="active">
<a href="#add" data-toggle="tab"><i class="icon-plus"></i>
<?php echo ('adicionar avaliação');?>
</a>
</li>
</ul>
</div>
<div class="box-content padded">
<?php echo form_open('admin/avalia/create' , array('class' => 'form-horizontal validatable','target'=>'_top'));?>
<div class="tab-content">
<div class="action-nav-normal">
<div class=" action-nav-button" style="width:300px;">
<a href="#" title="Users">
<img src="<?php echo base_url();?>template/images/icons/exam.png" />
<span>Total de <?php echo count($avalias);?> Avaliações</span>
</a>
</div>
</div>
<div class="tab-pane active" id="add">
<form action="" method="post">
<div class="form-actions">
<label style="display: block">
<input class="btn btn-gray" type="button" name="add" value="Adicionar Pergergunta" />
<button type="submit" class="btn btn-gray"><?php echo ('Salvar Avaliação');?></button>
</label>
</div>
</br>
<div class="control-group">
<label><?php echo ('Avaliação:');?>
<input type="text" class="" name="titulo"/>
</label>
</div>
<label style="display: block">Pergunta: <input type="text" name="pergunta"></label>
<fieldset id="inputs_adicionais" style="border: Pergunta" name="pergunta2">
</fieldset>
</form>
</div>
</div>
</div>
</div>
<-- GERANDO FORMULÁRIOS ADICIONAIS -->
<script type="text/javascript">
$(document).ready(function(){
var input = '<label style="display: block">Pergunta: <input type="text" name="pergunta" /> <a href="#" class="remove">X</a></label>';
$("input[name='add']").click(function( e ){
$('#inputs_adicionais').append( input );
});
$('#inputs_adicionais').delegate('a','click',function( e ){
e.preventDefault();
$( this ).parent('label').remove();
});
});
</script>
Segue o código do controller:
function avalia($param1 = '', $param2 = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');
if ($param1 == 'create') {
$data['avalia_id'] = $this->input->post('avalia_id');
$data['titulo'] = $this->input->post('titulo');
$data['pergunta'] = $this->input->post('pergunta');
$this->db->insert('avalia', $data);
redirect(base_url() . 'index.php?admin/avalia/', 'refresh');
}
if ($param1 == 'edit' && $param2 == 'do_update') {
$data['avalia_id'] = $this->input->post('avalia_id');
$data['titulo'] = $this->input->post('titulo');
$data['pergunta'] = $this->input->post('pergunta');
$this->db->where('avalia_id', $param3);
$this->db->update('avalia', $data);
redirect(base_url() . 'index.php?admin/avalia/', 'refresh');
} else if ($param1 == 'edit') {
$page_data['edit_data'] = $this->db->get_where('avalia', array(
'avalia_id' => $param2
))->result_array();
}
if ($param1 == 'delete') {
$this->db->where('avalia_id', $param2);
$this->db->delete('avalia');
redirect(base_url() . 'index.php?admin/avalia/', 'refresh');
}
$page_data['avalia'] = $this->db->get('avalia')->result_array();
$page_data['page_name'] = 'avalia';
$page_data['page_title'] = ('Avaliação');
$this->load->view('index', $page_data);
}
I would like to know how to save the additional fields generated in banco de dados
.