php(codeigniter) set default value with form helper -
i have form used different action(inserting , updating). use isset
function updating purpose. complete code :
<div id="form_daftar"> <?php echo form_open($action) ?> <?php if($action === 'backend/pengurus/add') $pengurus['email'] = ''; ?> <p id="input_nama"> nama : <?php echo form_input('txt_nama', isset($pengurus['nama'])?$pengurus['nama']:"");?> </p> <p id="input_email"> email : <?php echo form_input('txt_email', isset($pengurus['email'])?$pengurus['email']:"");?> </p> <p id="input_password"> password : <?php echo form_password('txt_pengurus');?> </p> <p id="input_alamat"> alamat : <?php echo form_input('txt_alamat', isset($pengurus['alamat'])?$pengurus['alamat']:"");?> </p> <p id="input_tanggal_lahir"> tanggal lahir : <input type="text" id="datepicker" name="datepicker" value="<?php echo isset($pengurus['tanggal_lahir'])?$pengurus['tanggal_lahir']:""?>"/> </p> <?php $action === 'backend/pengurus/add' ? $label = "daftarkan pengurus" : $label = "update data pengurus"; echo form_submit('btn_insert', $label); ?> <?php echo form_close(); ?> </div>
however, got weird bug isset not working correctly. so, tried add piece of code (snippet above) :
<?php if($action === 'backend/pengurus/add') $pengurus['email'] = ''; ?>
however, $pengurus['email']
not recognized, although recognized in form below code (look complete code).
what should do?
any appreciated, please ask me if dont understand question (english not native languange). thanks:d
for setting default values form inputs in ci, use set_value(), like:
<?php echo form_input('txt_nama', set_value('txt_nama', ''));?>
Comments
Post a Comment