Welcome Guest, Not a member yet? Register   Sign In
how to repopulate readonly input form
#1

[eluser]pvperez1[/eluser]
Hi guys,

I'm new to codeigniter.

I have a group of form that repopulates from database data. This group of form is on an edit page of the site i'm creating.

One of the input fields is readonly (id of the record), because I want the user to see the record ID of what she is editing, however, if that person made a mistake in filling the other forms, the page will reload because of form_validation. All the other fields retain their value except for the readonly form, and you cannot put anything on it because its readonly.

Here is the code in my view:

<div class='form-inline'>
<div class='input-group'>
<div class="input-group-addon">Book ID:</div>
&lt;input class="form-control" type="text" name="bookID" value="&lt;?php echo set_value('bookID',(isset($results[0]-&gt;id)) ? $results[0]->id : '');?&gt;" readonly>
</div>
</div>

Thanks everyone
#2

[eluser]CroNiX[/eluser]
Do you have a form validation rule for that field?
#3

[eluser]pvperez1[/eluser]
Hi CroNiX,

I did not put form validation for the readonly field, but i do have form validation for the other fields that the user can edit.

If the user failed form validation, the forms reloads, the other fields maintain their value bec of set_value, while the readonly field does not
#4

[eluser]CroNiX[/eluser]
That's why it's not repopulating. Create a trim rule for it or something. If you use validation, all form fields need a rule in order to repopulate.
#5

[eluser]pvperez1[/eluser]
that makes sense, thanks!

i didn't use form validation because i know that the data in the readonly field is correct, but now, i tried validating the readonly field with just trim and now it repopulates, thanks again!
#6

[eluser]CroNiX[/eluser]
Don't trust any input from forms. Just because a field is read only doesn't mean that it can't be manipulated using the browsers developer tools, firebug, and a lot of other tools. You can directly change anything on the page. You might use a better rule than just trim to validate that whatever format the id is supposed to be in is correct. I suggested using trim because I just wanted to show you that it needs a rule to repopulate.




Theme © iAndrew 2016 - Forum software by © MyBB