Welcome Guest, Not a member yet? Register   Sign In
i have a problem with set_value() for two textareas
#1

[eluser]popa_tudor[/eluser]
Code:
$addDesc =  array(
            'name' => 'descriere',
            'id' => 'descriere',
            'rows' => '3',
            'cols' => '30',
            'class' => 'formInput'
            );
$addIngr =  array(
            'name' => 'ingrediente',
            'id' => 'ingrediente',
            'rows' => '3',
            'cols' => '30',
            'class' => 'formInput'
            );
<tr>
    <td valign="top" class="formInputName">Descriere:</td>
    <td>&lt;?php echo form_textarea($addDesc, set_value('descriere')); ?&gt;</td>
  </tr>
  <tr>
    <td valign="top" class="formInputName">Ingrediente:</td>
    <td>&lt;?php echo form_textarea($addIngr, set_value('ingrediente')); ?&gt;</td>
  </tr>

I have two textareas inside a form, they look the same and should function in the same manner, but they don't and I don't see the mistake.
When I submit the form, in case form validation fails, there should be error messages and the fields should contain the previous values. The first textarea does that all the time, like it's expected. But the second textarea 'ingrediente' never keeps the value.
I cannot spot the error, or explain the behaviour.
Please help.
#2

[eluser]InsiteFX[/eluser]
Your missing your value in your arrays!
The value variable is what is set when you click submit.

InsiteFX
#3

[eluser]popa_tudor[/eluser]
how do i miss the values? i dont get it. i did the same form but with only one textarea and it works. whats different with two textareas? an where should i look for the error?
#4

[eluser]InsiteFX[/eluser]
Sorry, I meant id but you already have that.
To show errors you need to add this in your view file:
Code:
// use yuor on field names that match
&lt;?php echo form_error('form_field'); ?&gt;
// or this will show all errors place after form_open
&lt;?php echo validation_errors(); ?&gt;

I I think you need to read the CodeIgniter User Guide on the Form_Validation Library and Form_helper.

InsiteFX
#5

[eluser]popa_tudor[/eluser]
thanks for the guidance, it seems i have to set a form_validation rule for each field i want to store previous values. for the first textarea the rule was min_length, but for the second one I had no rule defined, therefore no post value.
I actually found the explanation here
Thanks again.
#6

[eluser]Andy UK[/eluser]
Yeah, that's right. Just set an empty rule so that you can then recover the values for those other two fields. Codeigniter doesn't retain input values for use with set_value() unless there is a validation rule for the field.
#7

[eluser]Vipin K. Singh[/eluser]
[quote author="popa_tudor" date="1304860460"]thanks for the guidance, it seems i have to set a form_validation rule for each field i want to store previous values. for the first textarea the rule was min_length, but for the second one I had no rule defined, therefore no post value.
I actually found the explanation here
Thanks again.[/quote]
Thanks a lot




Theme © iAndrew 2016 - Forum software by © MyBB