Jump to content


Add one fake field As dropdown?

fakefield dropdown

  • Please log in to reply
1 reply to this topic

#1 sureshkumar039

sureshkumar039

    Newbie

  • Members
  • Pip
  • 6 posts

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...



#2 kenshicu

kenshicu

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationHolguĂ­n, Cuba

Posted 16 July 2013 - 01: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.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users