Welcome Guest, Not a member yet? Register   Sign In
example of CRUD w/form_validation
#1

[eluser]pettechservices[/eluser]
I'm trying to see if anyone can point me in the direction of a tutorial that shows a simple crud application with the newer form_validation???

I'm not really understanding how to use 1 form for ADD/EDIT with form_validation. I know the set_value has a second option to have a default in the field, but if I'm using the form for a new record (add mode), i wouldn't have anything in the 2nd variable, which would then result in an error (or notice??).

I'm just kinda lost here, and have spent a couple of days looking in the forums and google.

PLEASE... Thank you!
#2

[eluser]CI_avatar[/eluser]
you may need to review this guide http://ellislab.com/codeigniter/user-gui...ation.html

"if I’m using the form for a new record (add mode), i wouldn’t have anything in the 2nd variable" just to some if else conditions in set_value
#3

[eluser]pettechservices[/eluser]
Thanks.. I should have been more clear, I have read the user guide so many times I'm having dreams about it. It briefly mentions set_value being able to have a default value, but does not go into details about populating form from db.

So the only way around it is using like an isset if else in the second var of set_value??
#4

[eluser]Cristian Gilè[/eluser]
If you edit a record you have associated an ID, if you create a new record the ID doesn't exist before.

You can pass to your view an ID var set to 0 for a new entry and set to a value from db for an editing operation.
Then if the var ID is 0 the second parameter of set_value will be empty otherwise will be set to a value from db.

Cristian Gilè
#5

[eluser]Atharva[/eluser]
Yes, I guess you have to do that, or use @ in front of variables to suppress errors.
#6

[eluser]Paul Hernández[/eluser]
Hi:

I'm writting a form tu add/edit data.

To load the values of the fields in edit mode I loaded first from the database in the controller and then passing them to the view. In the view file I'm using the set_value function to populate the fields in this way:

Code:
<input type="text" name="urljornada" id="urljornada" value="<?php echo set_value('urljornada', @$url) ?>" class="myinputstyle"/>

If the form is loaded for the first time, the fields use the default value (2nd parameter of the set_value method).
If the form validation fail, the field value suppose to be the first parameter of the set_value method. The problem is the 2nd parameter throw an error because the variable is not present when the form is reload due to a validation failure. I followed the advice in this thread and putted a "@" preceding the variable name and that solved it, but is this the best/correct/intelligent/shorter/elegant way to do it?

I'm using CI2

Regards




Theme © iAndrew 2016 - Forum software by © MyBB