⚠ 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

Passing values to field_type hidden from $_SESSION



kolo78
  • profile picture
  • Member

Posted 16 June 2018 - 18:39 PM

Hello Everybody, 

 

I'm struggling with a problem, I tried several ways to accomplish this with no lucky.

 

I need to pass a value: tbl_asegurado_fenixid to the add form. I have this value already saved in a $_Session ... but don't know why isn't populate on the DB...

 

This is my code,

public function index()
    {
    	$this->global['pageTitle'] = 'Fenix : Mis Fenix';
	    $fenixidget =$this->input->get('fenixid');

	    $this->session->set_userdata('fenixid', $fenixidget);

	    echo $_SESSION['fenixid'];

       $this->cargarasegurados();

    }

	public function cargarasegurados()
	{
		$crud = new grocery_CRUD();
		echo $id_insertar;
		$crud->set_theme('datatables');
		$crud->set_table('asegurado');
		$crud->set_subject('Asegurados');

		//$crud->unset_add();
		$crud->unset_clone();
		$crud->unset_delete();
		$crud->unset_export();
		$crud->unset_print();

		$crud->columns('tbl_asegurado_fenixid','tbl_asegurado_nombre',
						'tbl_asegurado_dni','tbl_asegurado_catastro','tbl_asegurado_telefono');

		$crud->fields('tbl_asegurado_fenixid','tbl_asegurado_nombre',
			'tbl_asegurado_dni','tbl_asegurado_catastro','tbl_asegurado_telefono');

		$crud->field_type('tbl_asegurado_fenixid', 'hidden', $_SESSION['fenixid']);

		//$crud->display_as('tbl_asegurado_fenixid','Fenix_ID');

		$crud->where('tbl_asegurado_fenixid', $_SESSION['fenixid']);

		$output = $crud->render();
		$this->global['pageTitle'] = 'Fenix : Asegurados';

		$this->loadViews("asegurados",$this->global,$output,"NULL");


	}

The session is working fine for the WHERE condition.

 

Any help will be higly appreciated!

 

Regards,

Pablo

 

--- Added Information ---

 

I've also tried with the following code

$crud->callback_add_field('tbl_asegurado_fenixid',function(){
			return '<input type="text" maxlength="50" value="'. $_SESSION['fenixid']  .'" name="tbl_asegurado_fenixid
">';


		});

kolo78
  • profile picture
  • Member

Posted 16 June 2018 - 19:20 PM

Problem solved, in case someone else experienced the same issue:

if (isset( $_GET['fenixid']))
    	{
		    $fenixidget =$this->input->get('fenixid');

		    $this->session->set_userdata('fenixid', $fenixidget);

		    echo $_SESSION['fenixid'];
	    }

This need to be done, to avoid the controller to overwrite the session variable with NULL