[eluser]aquary[/eluser]
PhilTem, that'd be the same for him since he still have to put a code that annoy him in the view:
Code:
isset($data['name'])?$data['name']:''
From the topic, I'm assuming you are trying to use one form for both editting and creating. Although a little bit different, I've been using the same method and didn't found it to be that much annoying, compare to having to maintain 2 copy of form for editting and creating....
However, I'd suggest you to create a dummy $data before sending to the edit view... but this will add some code to your controller or model any way.
Code:
// Controller
function save($id=NULL){
// assume this return a row of data from DB
if(!empty($id))
$data['data']=$this->the_model->get_data($id);
else{
// do whatever to get an empty data with the same structure
// In this case, do a lazy way right here.
$data['data']['input_name']='';
$data['data']['input_name2']='';
// or modify your get_data() function to return a structure of the data. in that case, you could even remove thw whole IF, and use only the get_data() row.
}
if($this->input->post() && $this->form_validation->run()){
// do save command
redirect('somewhere');
}
$this->load->view('edit', $data);
}
This way, since the data is always exists, you don't have to check if the data exist or not. However, IMO, there might be more annoyance since you'll have to keep track of the data structure in the controller as well, instead of focusing on one view file, and put the checking while you are adding fields...
btw, you could use empty() instead of isset().
Code:
<input type="text" name="name" value="<?php echo set_value('name', empty($data)?'':$data['name']); ?>">