⚠ 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

Hidden fields



Kor
  • profile picture
  • Member

Posted 21 December 2012 - 20:24 PM

Hello again Johnny!

It's been quite while, huh? What a incredible tool you've created here. Thanks man! :)

Now... a question: How do I create a hidden field that is not part of any database and belongs to no table at all?
Let me explain... I added an action with add_action which calls another CRUD passing the ID through the link, where I retrieve it with GET. Now, that only works once. So, if I add or edit some item on my list, that filter is lost. I thought that I could keep it creating a hidden field. But, when I tried to create it with add_fields or edit_fields, I get this error:


[b] A PHP Error was encountered[/b]

Severity: Notice
Message: Undefined index: filtra_apontamento
Filename: controllers/titulos.php
Line Number: 70
filtra_apontamento is the hidden field I'm trying to create. Here it is the code:


$this->grocery_crud->add_fields('filtra_apontamento');
$this->grocery_crud->edit_fields('filtra_apontamento');
$this->grocery_crud->field_type('filtra_apontamento', 'hidden', $_GET['filtra_apontamento']);


And there's also another question: How do I use the value of this created field, assuming it is possible to create it, on my filter parameters at

$this->grocery_crud->where('titulo.apontamento_id', <what it goes here?>);


Thanks for any help you may provide. ;)

victor
  • profile picture
  • Member

Posted 21 December 2012 - 20:31 PM

HI! Show your url for the "add_action".

Kor
  • profile picture
  • Member

Posted 21 December 2012 - 20:41 PM

Hi Victor! Thanks for answering! ;)

I've found an error on


$this->grocery_crud->field_type('filtra_apontamento', 'hidden', $_GET['filtra_apontamento']);


It is instead


$this->grocery_crud->field_type('filtra_apontamento', 'hidden', $_GET['apontamento_id']);


The error is no longer, but I've looked at the source code of my page and found no hidden fields in the code.

Here it is the data you requested

This is the link

$this->grocery_crud->add_action('Ver Títulos', '/imagens/Document-Copy-icon.png', '', '', array($this,'set_url'));


This is the function that generates the link


function set_url($primary_key, $row){

return (site_url('titulos/?apontamento_id=' . $row->apontamento_id));

}

victor
  • profile picture
  • Member

Posted 21 December 2012 - 20:48 PM

You should to use a segment as solution.

for example you have this url to the function:

[quote]
http://my_site.com/c...oller/function/
[/quote]


return (site_url('controller/function/' . $row->apontamento_id));

then:

$this->grocery_crud->where('titulo.apontamento_id', $this->uri->segment(3));

It works perfectly.

Kor
  • profile picture
  • Member

Posted 21 December 2012 - 20:54 PM

Thanks Victor!

This was an elegant solution. :D

victor
  • profile picture
  • Member

Posted 21 December 2012 - 21:25 PM

Regards :D