Welcome Guest, Not a member yet? Register   Sign In
_form for edit and for add
#1

[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'); ?>
<?php echo form_input('firstname', $user->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?
#2

[eluser]kurucu[/eluser]
Perhaps the Query-Colon syntax?
Code:
<?php echo form_input('firstname', (isset($user) ? $user->FirstName : '') ; ?>
If you aren't familiar, it takes the first as a condition, returns the second if true and the third if false.

Otherwise, perhaps prep a class either way, so that you have an user class being sent to the Add form with empty values.
#3

[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') : '') ; ?>
#4

[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;
I check for the submit value, if its true (is an edit) then use the posted form value if not use the db value:
Code:
<?php echo form_input('firstname', ($is_edit) ? set_value('firstname') : $user_data['firstname']) ; ?>




Theme © iAndrew 2016 - Forum software by © MyBB