⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Add one fake field As dropdown?



sureshkumar039
  • profile picture
  • Member

Posted 16 July 2013 - 12:54 PM

How Can i add one fake field ie; dropdown..

In my database category field is not there. But in my form i will add dropdown for category. So how can i add fake dropdown field?.

 

Please give any solution...


kenshicu
  • profile picture
  • Member

Posted 16 July 2013 - 13:24 PM

to add fakefield

$crud->fields('fiel1','field2','fakefield','field4');

to eliminate post array fakefield

$crud->callback_before_insert(array($this,'_callback_before_save'));
$crud->callback_before_update(array($this,'_callback_before_save'));

put data to selectbox created (this is an example, if not functional)

$crud->callback_field ( 'fakefield', array ( $this, '_callback_field_fakefield' ) ); 

functions

function _callback_before_save($post_array)
{
	unset ( $post_array['fakefield'] );
       return $post_array;
}
	
function _callback_field_fakefield($value = '', $primary_key = null)
 {   
	$table	=	'your table name';
	$id_fakefield	=	'your id field';
	$desc_fakefield	=	'your description field';
	$data_placeholder	=	'select your data';
	
		$this->db->select ( 'id_fakefield,desc_fakefield' );
		$this->db->from ( $table );
		$result = $this->db->get ();
		
	$html .= '<select name="'.$id_fakefield.'" class="chosen-select" data-placeholder="'.$data_placeholder.'" style="width: 200px;">';
	$html .= '<option value=""></option>';
	foreach ($result->result_array() as $row)
	{
	$html .= '<option value="'.$row[$id_fakefield].'" >'.$row[$desc_fakefield].'</option>';
	}
	$html .= '</select>';
	return $html;
 }

this code have not tried it as well as it is.