Multidimensional form arrays in Code Igniter

by gowtham 2010-09-17 11:24:49

function Fixes()
{

$this->form_validation->set_error_delimiters('<p class="error">', '</p>');

$this->form_validation->set_rules('name_field[]','Name of fix','trim|required|min_length[5]|max_length[100]');
$this->form_validation->set_rules('desc_field[]','Description of fix','trim|required|min_length[10]|max_length[1000]');
$this->form_validation->set_rules('url_field[]','URLs','trim|required|callback__Check_URL_Format');
$this->form_validation->set_rules('num','','trim|required|num');

if($this->form_validation->run())
{

}


echo "post ".$this->input->post('num');

if($this->input->post('num'))//Num = number of fixes so far.
$options->num = $this->input->post('num');
else
$options->num=1;

echo "skdjksjf ".$options->num;
$this->load->view('add/step2',$options);
}

My form in views/step2

<?=form_open(base_url().'add/fixes');?>

<fieldset>
<legend><h2>Add Fixes</h2></legend>

<? for($i=0;$i<$num;$i++): ?>

<div class="duplicates duplicate_<?=$i?>">
<h4>Fix #<?=$i?></h4>
<div class="form_row">
<div class="form_field">
<label for="name_field">Name of Fix</label>
</div>
<div class="form_field">
<?
//form_input("name_field[]",set_value("name_field[]"));
?>
<input type="text" name="name_field[]" value="<?=set_value("name_field[($i+1)]")?>" />
<?=form_error("name_field[($i+1)]");?>
</div>
</div>

<div class="form_row">
<div class="form_field">
<label for="name_field">External links (URLs) to fixes (One link on each line.).</label>
</div>
<div class="form_field">
<?=form_textarea('url_field[]',set_value('url_field[]',"http://"),'class="content"');?>
<?=form_error('url_field[]');?>
</div>
</div>

<div class="form_row">
<div class="form_field">
<label for="desc_field">Describe how to perform the fix.</label>
</div>
<div class="form_field">
<?=form_textarea('desc_field[]',set_value('desc_field[]'),'class="content"');?>
<?=form_error('desc_field[]');?>
</div>
</div>

</div>
<? endfor; ?>

<div class="form_row">
<div class="form_field">
<?=form_button('add_more','Add Another Fix','id="add_more"');?>
</div>
</div>


<div class="form_row">
<div class="form_field">
<?=form_hidden('num',set_value('num',1),'id="num"');?>
<?=form_submit('submit','Next Step >');?>
</div>
</div>

</fieldset>

<?=form_close();?>

Tagged in:

1299
like
0
dislike
0
mail
flag

You must LOGIN to add comments