Return back values to view if any error in form fields - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: Return back values to view if any error in form fields (/showthread.php?tid=67748) |
Return back values to view if any error in form fields - MuhamedAuda - 04-04-2017 Hello all I created view and controller and model successfully Every thing is fine except one enhancement: When submit data to controller if error found in sent input values from view then the controller redirect to view again(form). Now how can i return back the sent data to view !! Can anyone send a link to example or idea of doing that, thanks .. RE: Return back values to view if any error in form fields - PaulD - 04-04-2017 It is well documented here in form_validation library docs: https://www.codeigniter.com/user_guide/libraries/form_validation.html#re-populating-the-form And here in the form_helper helper docs: https://www.codeigniter.com/user_guide/helpers/form_helper.html#set_value Basically, if your input name is 'user_name' you repopulate the value using something like: PHP Code: <input type="text" name="user_name" value="<?php echo set_value('user_name', ''); ?>" /> Where the second value is the default value, commonly blank. Paul. RE: Return back values to view if any error in form fields - MuhamedAuda - 04-04-2017 Quote: It is well documented here in form_validation library docs: Thanks Paul for replaying me. Yes I got that but I built the form filed like this: Code: <?php echo form_input($in_VINn_attributes); ?> and input attributes from array: Code: $in_VINn_attributes = array( How can I process set_value method with that!! RE: Return back values to view if any error in form fields - MuhamedAuda - 04-04-2017 Hello thanks Paul But I used the following to create input: Code: <?php echo form_input($in_cylinder_attributes); ?> and I test that : Code: <?php echo form_input($in_cylinder_attributes, set_value('cylinder')); ?> it give me no thing ! RE: Return back values to view if any error in form fields - PaulD - 04-05-2017 It is not something I use but try just adding the value as an attribute in your attributes list, as it is just an attribute pair. Something like: PHP Code: // set default I hope that helps. Paul. PS Not sure about this but will test for you now. Back soon... RE: Return back values to view if any error in form fields - PaulD - 04-05-2017 Yes works fine. Controller: PHP Code: // set data for test input field View: PHP Code: <?php echo form_open(); ?> Just make sure you have both the form helper loaded and the form_validation library loaded. Best wishes, Paul RE: Return back values to view if any error in form fields - MuhamedAuda - 04-06-2017 Thanks Paul, Yes it work fine. I have found I used redirect() instead of $this->load->view('view.php', $data) So it never got data back to view. Now : Don't use redirect() to go view use: $this->load->view so set_value() work fine .. |