HI guys how can i use same form for edit and add data into database? |
[eluser]Waqar[/eluser]
I want to use one form for both edit and delete data into database but i am not understanding how I can do that?
[eluser]Waqar[/eluser]
Yeah sorry about the mistake i want to insert and update in the same view
[eluser]umefarooq[/eluser]
Hello waqar your add and edit are two different function of your controller, if you are using form helper for your form development in add function leave blank value section, while in edit function put your fatched records value add function Code: $data['title'] = array('name'=>'name','id'=>'name'); edit function Code: $row = fetch record from model; and your view Code: <?=form_input($title)?> try this it will work
[eluser]n0xie[/eluser]
[quote author="pistolPete" date="1239129694"]Insert and update in the same view[/quote] Click there. You will find http://codeigniter.com/wiki/Add_Edit_Views/
[eluser]Waqar[/eluser]
Here is my controler Code: function add_edit() model Code: function add_individual() Code: $attributes = array('class' => 'indvidual', 'id' => 'individualform');
[eluser]Waqar[/eluser]
I am not understanding how to use the values in the form field if id is present coz it is giving me severity error.
[eluser]umefarooq[/eluser]
hi nothing is difficult now u have to modify little things in code and in you database table there should be one field name id or what ever you like as a key to update your record and it can be your auto increment key in your table also add function Code: $data['title'] = array('name'=>'name','id'=>'name'); edit function Code: $row = fetch record from model; and your view Code: <?=form_input($title)?>
[eluser]Waqar[/eluser]
I am having problem loading the view form with values. it will load the edit form but when i click on add it will give me severity error and undefined row Quote:<?php help would be appreciated;
[eluser]umefarooq[/eluser]
hi you are no following the MVC pattern that's why you are getting this error your code should be in you controller, that' you are getting error here is your code will be like this Model Code: function get_record($id){ controller Code: if($this->uri->segment(3)){ View Code: <input type=“hidden” name=“id” value=”<?=$row->id?>” > you code will be clean |
Welcome Guest, Not a member yet? Register Sign In |