![]() |
help: losing uri segment when failing form validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: help: losing uri segment when failing form validation (/showthread.php?tid=32015) |
help: losing uri segment when failing form validation - El Forum - 07-10-2010 [eluser]pabloheim[/eluser] Hi first of all , sorry for my english ![]() im having some trouble with the process of editing an item which id is taken from a uri segment. all is fine if you dont commit any mistake. if form validation fails, the page is reloaded but this time without the uri element corresponding to the id. Here is an example of the situation: Code: function edit(){ Ok, so when i enter into the edit page , the url is like: Code: localhost/app/index.php/controller/edit/4 If you submit the form and valdation fails, all is reloaded but the url is like: Code: localhost/app/index.php/controller/edit So the id is lost and there is no reference to the element that i wanted to edit. The first solution was to keep the id in a session, with is code: Code: function edit(){ this works, but i think its a little bit complex. please, can you suggest another way to do this?? Thanks in advance!! help: losing uri segment when failing form validation - El Forum - 07-10-2010 [eluser]WanWizard[/eluser] If the URL is different upon submitting a form, check the form action in your page source. Does it contain the '4' or is it already stripped there? help: losing uri segment when failing form validation - El Forum - 07-10-2010 [eluser]pabloheim[/eluser] [quote author="WanWizard" date="1278796962"]If the URL is different upon submitting a form, check the form action in your page source. Does it contain the '4' or is it already stripped there?[/quote] Hi, thanks for comment. in the form, the url in the action attribute the same asthe controller Code: <?php echo form_open('controller/edit');?> as you can see, it doesnt contain the id. im putting it in a hidden input : Code: <?=form_hidden('id_item',$id_item)?> //comes from the $data['id_item'] in the controller help: losing uri segment when failing form validation - El Forum - 07-12-2010 [eluser]Flemming[/eluser] what I said was a load of rubbish so I deleted it! help: losing uri segment when failing form validation - El Forum - 07-12-2010 [eluser]Flemming[/eluser] OK second attempt! At the very top of your edit() method, above the validation IF, put the $id into a variable like this: Code: $edit_id = $this->uri->segment(3); that should solve your problem I think help: losing uri segment when failing form validation - El Forum - 07-12-2010 [eluser]WanWizard[/eluser] [quote author="pabloheim" date="1278797691"]in the form, the url in the action attribute the same asthe controller Code: <?php echo form_open('controller/edit');?> Code: <?=form_hidden('id_item',$id_item)?> //comes from the $data['id_item'] in the controller So it's quite logical that after you submit the form the id is no part of the URI, since you didn't include it. You have to retrieve it from the posted form. I recommend not to use $this->input->post(), but to validate it properly using the form validation library, and after validation use set_value() to access the ID variable. |