Optional Default Value |
I am new to CodeIgniter, I love it! So simple!
I'm getting to know the basics so I'm creating a user management system. Logging in, out and registering all works fantastic. I am currently working on the editing of the profile. I want the default value of the input fields to be the session variable of first_name and last_name however if the form has been posted I want the default value to be the post variable instead. This is my application/views/profile/edit.php. PHP Code: <div class="container"> I hope I have made this easy enough to understand, Thank you in advance!
You could create a $first_name and $last_name variable before the form that takes the POST data if available, else take the session data. This would be for if you refresh the same page on form submit.
Something like this PHP Code: <?php
Is set_value() not working for you? I've looked at the code, and it seems that, the first time through, the value displayed would be $this->session->userdata('logged_in')['first_name']) and only on second and subsequent displays would be value come from the value entered in the field. Odd.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
This is how I handle "form field population", taylored to your specific case. Make of it what you will.
View file: Code: <input type="text" name="field_name" value="<?php echo htmlentities($post['field_name']) ?>"> In your controller... Code: ...
(02-28-2015, 01:00 PM)silentium Wrote: You could create a $first_name and $last_name variable before the form that takes the POST data if available, else take the session data. This would be for if you refresh the same page on form submit. Thank you, mate. I used your method, slightly differently. I'm trying to keep the as much if/else statements out of the view files so I added to the controller. PHP Code: $data = array( (03-01-2015, 06:08 AM)miiikkeyyyy Wrote: Thank you, mate. I used your method, slightly differently. Adding the if/else to the controller is definitely the right way to do go. Just added it above you HTML for simplicity in showing how to do it |
Welcome Guest, Not a member yet? Register Sign In |