Return back values to view if any error in form fields |
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 ..
It is well documented here in form_validation library docs:
https://www.codeigniter.com/user_guide/l...g-the-form And here in the form_helper helper docs: https://www.codeigniter.com/user_guide/h...#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.
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!!
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 !
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...
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
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 .. |
Welcome Guest, Not a member yet? Register Sign In |