![]() |
_form for edit and for add - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: _form for edit and for add (/showthread.php?tid=22900) |
_form for edit and for add - El Forum - 09-23-2009 [eluser]bas_vdl[/eluser] is there a way to use the same from for the add and edit actions? i want to create a _from.php (tempalte form) and then use it for the add and edit actions. the problem i'm facing at the moment is in the edit form i use: Code: <?php echo form_label('Voornaam', 'firstname'); ?> If i use the same code in the add form i get the error non object etc. i can supress the error by using an @-sign in front of $user->FirstName but thats not really nice? any idea? _form for edit and for add - El Forum - 09-23-2009 [eluser]kurucu[/eluser] Perhaps the Query-Colon syntax? Code: <?php echo form_input('firstname', (isset($user) ? $user->FirstName : '') ; ?> Otherwise, perhaps prep a class either way, so that you have an user class being sent to the Add form with empty values. _form for edit and for add - El Forum - 09-23-2009 [eluser]bas_vdl[/eluser] not sure if that is going to work... this is what we want... for an edit form default the DB value unless there is a $_POST: Code: <?php echo form_input('firstname', (isset($_POST) ? set_value('firstname') : $user->FirstName) ; ?> for an add form default '' unless there is a $_POST Code: <?php echo form_input('firstname', (isset($_POST) ? set_value('firstname') : '') ; ?> _form for edit and for add - El Forum - 10-28-2009 [eluser]CroNiX[/eluser] I know its a bit old, but I wouldnt check to see if post is set...as you might be passing other data via post not related to your form. What I usually do is at the top of the view page have something like: Code: $is_edit = ($this->input->post('submit')) ? TRUE : FALSE; Code: <?php echo form_input('firstname', ($is_edit) ? set_value('firstname') : $user_data['firstname']) ; ?> |