Welcome Guest, Not a member yet? Register   Sign In
Edit form and validation... big problem
#1

[eluser]ariok[/eluser]
Hi!
I have a question (that i hope could find an answer... -.-) about the validation class..

it's really hard for me understand how to manage a form where i have dinamic fields..

In my edit Form i have these steps:
1) load page taking data from db and set input value with this data.
2) send data
3) if there are some errors, load again edit form with $this->validation->fieldname value
rather than Db value as values for input field.

here some parts of my view code:

This is for input text field :
Code:
<input id="username" name="username" type="text" value="<? echo ($this->validation->username!=false or $this->validation->username_error!="") ? $this->validation->username : $userdata->username ;?>"/>

So for this situation is ok.. but if have dinamic fields in my form...
(like list of permissions with a checkbox to assign permissions to a users)... what i have to do?!?

I try to generate fields dinamicaly with this code in my controller
Code:
foreach ($queryAllGrp->result_array() as $ngrp) {    
            $fields["id".$ngrp['id']] = "id{$ngrp['id']}";
        }
        $this->validation->set_fields($fields);

and set view in this mode..($allGrp contain $queryAllGrp->result_array());

Code:
<table border='1'>
    &lt;? foreach($allGrp as $grp): ?&gt;
         <tr>
            <td>&lt;input type="checkbox" name="id&lt;?=$grp["id"]?&gt;" value="&lt;?=$grp["id"]?&gt;" &lt;? $var ="id".$grp['id']; echo ($this-&gt;validation->$var!=false) ? $this->validation->set_checkbox('id'.$grp["id"],$grp["id"]) : isMyGrp($grp["id"],$myGrp);?&gt; /> </td>
         </tr>
    &lt;? endforeach; ?&gt;
    </table>

But it seems that ($this->validation->$var!=false) is not the right way..
.. uhm... too confused... !!!!

is there a way to do this??
is not so strange to have dinamic form!! Big Grin

thank you all .. and sorry for my terrible English
#2

[eluser]ELRafael[/eluser]
Validation on checkbox, radiobutton, select works a little different!

You'll need to list all the checks. And set if the selected checkbox id is the same of your list of checks id.

i didn't use validation in checkbox yet, but i used in select. Look what i've done

Code:
&lt;select name="tu_codigo" id="tu_codigo" onchange="professor_codigo();"&gt;
     &lt;?php foreach ($tipos_usuarios->result() as $tipos) : ?&gt;
       <option value="&lt;?=$tipos->tu_codigo;?&gt;" &lt;?= $this->validation->set_select('tu_codigo', $tipos->tu_codigo); ?&gt; >
        &lt;?=$tipos->tu_descricao;?&gt;
       </option>
     &lt;?php endforeach; ?&gt;
</select>

So, if the selected option (tu_codigo) is equal of list of foreach ($tipos->tu_codigo), there will be selected, understand?

About yuor english, never mind! I don't spoke too :gulp:




Theme © iAndrew 2016 - Forum software by © MyBB