Welcome Guest, Not a member yet? Register   Sign In
Bug. Form validation fails if form array element is empty
#8

[eluser]Mikhail Menshinskiy[/eluser]
See:
Codeigniter User Guide: Form validation

Quote:If you do use an array as a field name, you must use the EXACT array name in the Helper Functions that require the field name, and as your Validation Rule field name.

In this topic discussed another question.

And your problem is an uncorrect working with CI library. And you have no a problem described above.

You should:

1. In controller: load "form_validation" library

2. set up of validation rules. For your example
Code:
$this->form_validation->set_rules('selec[]', 'Seleccion', 'required');
$this->form_validation->set_rules('recibo[]', 'Recibo', 'trim|required');
$this->form_validation->set_rules('fecha[]', 'Fecha', 'trim|required');
$this->form_validation->set_rules('importe[]', 'Importe', 'trim|required');

3. If validation is failed then load a view:
Code:
if ($this->form_validation->run() === FALSE)
{
    $this->load->view('test');
}
else
{
    echo "SUCCESS";
}

4. In view:
Code:
&lt;?php for ($i=0; $i<=3; $i++): ?&gt;
    
&lt;input name="fecha[]" type="text" id="fecha" size="10" value="&lt;?php echo set_value("fecha[]", date("d-m-Y")); ?&gt;" /&gt;
&lt;input name="recibo[]" type="text" id="recibo" size="10" value="&lt;?php echo set_value("recibo[]"); ?&gt;" /&gt;
&lt;input name="importe[]" type="text" id="recibo" size="10" value="&lt;?php echo set_value("importe[]"); ?&gt;" /&gt;
&lt;input name="selec[]" type="checkbox" id="selec" value="&lt;?php echo $i;?&gt;" &lt;?php echo set_checkbox("selec[]", $i); ?&gt; /&gt;
<br/>
    
&lt;?php endfor; ?&gt;

And please read a Codeigniter Guide for more information.
Good luck =)


Messages In This Thread
Bug. Form validation fails if form array element is empty - by El Forum - 04-28-2011, 01:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB