• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

URL Parameter With Array - PHP List Plugin

tiagovareta

Member
Hi!

I have a PHP List button, to open a link (form).
When I click the button to open the link/form, I want to pass a parameter, with the id of the selected records.

I use this code:
$app = JFactory::getApplication();
$ids = $app->input->get('ids', array(), 'array');
$id = array_shift($ids);
$app->redirect('index.php?option=com_fabrik&view=form&formid=36&id_linha=' . $id);

It works, but it does not pass the array with the id of the selected registers, it passes only 1 id.

How can I pass an array with the various records selected?
 
Not sure what you mean. It's doing exactly what you are asking it to do. You get the $ids array, then you array_shift() the first value out of the array, and use that.

http://php.net/manual/en/function.array-shift.php

If you need to pass all the ids, as (say) a comma separated list ...

Code:
$app = JFactory::getApplication();
$ids = $app->input->get('ids', array(), 'array');
$app->redirect('index.php?option=com_fabrik&view=form&formid=36&id_linha=' . implode(',', $ids));

-- hugh
 
Not sure what you mean. It's doing exactly what you are asking it to do. You get the $ids array, then you array_shift() the first value out of the array, and use that.

http://php.net/manual/en/function.array-shift.php

If you need to pass all the ids, as (say) a comma separated list ...

Code:
$app = JFactory::getApplication();
$ids = $app->input->get('ids', array(), 'array');
$app->redirect('index.php?option=com_fabrik&view=form&formid=36&id_linha=' . implode(',', $ids));

-- hugh

Hi Cheesegrits!
Thank you one more time!!! That's what I wanted!

Now clicking the button opens the link / form, and passes the selected ids!

But in this form that opens, I have a field that does a query to the databases, to get the contact of the id that passed in the URL.
The code is as follows:

$myInput = JFactory::getApplication()->input;
$myParam = $myInput->get('id_linha','');
$db = FabrikWorker::getDbo();

$contactoassessor = "SELECT contacto_ctt FROM tb_contacto WHERE id_contacto_geral_ctt = '$myParam'";
$db->setQuery($contactoassessor);
$contacto_assessor = $db->loadResult();
return $contacto_assessor;

It was working, when the URL passed only 1 id selected.
Now the URL passes several ids separated by ";" (as intended), but now I can not separate the ids, to make the query.

Example:
If I pass the URL the ids: 1; 2; 3; 4; 5; 6
When calling the variable to do the query: $myParam = $myInput->get('id_linha','');
Set the value: "1; 2; 3; 4; 5; 6"
I intended to receive the ids separately, and then make the query ($contactoassessor = "SELECT contacto_ctt FROM tb_contacto WHERE id_contacto_geral_ctt = '$myParam'";), for each id.
 
Not sure what you mean. It's doing exactly what you are asking it to do. You get the $ids array, then you array_shift() the first value out of the array, and use that.

http://php.net/manual/en/function.array-shift.php

If you need to pass all the ids, as (say) a comma separated list ...

Code:
$app = JFactory::getApplication();
$ids = $app->input->get('ids', array(), 'array');
$app->redirect('index.php?option=com_fabrik&view=form&formid=36&id_linha=' . implode(',', $ids));

-- hugh

When calling the variable passed by the URL, for the field, the values get together:
$myInput = JFactory::getApplication()->input;
$myParam = $myInput->get('id_linha','');

return $myParam;

Image: http://prntscr.com/hzmeag
 
You can't do this if $myParam is something like 1,2,3
Use
WHERE id_contacto_geral_ctt IN ( $myParam)

Hi Troester!
Thanks for the answer!

When calling the variable passed by the URL, for the field, the values get together: http://prntscr.com/hzmeag
I use the code in the field:
$myInput = JFactory::getApplication()->input;
$myParam = $myInput->get('id_linha','');
return $myParam;

That is, in the URL has ";", when calling the variable it loses ";", to do the query the ids passed by the url have to maintain ";".
 
Are you using a semicolon in the implode() code I gave you instead of a comma?

If so, you probably can't do that, as ; is a reserved character and musn't be used in URL's unencoded.

-- hugh
 
Are you using a semicolon in the implode() code I gave you instead of a comma?

If so, you probably can't do that, as ; is a reserved character and musn't be used in URL's unencoded.

-- hugh

Hi Cheesegrits! I already signed :)

When I click the button, I pass the values as I want and separated by commas: http://prntscr.com/i16j59

When I call the variable in a field:
$myInput = JFactory::getApplication()->input;
$myParam = $myInput->get('id_linha','');
return $myParam;

Remove the commas by getting an integer: http://prntscr.com/i16khh

The idea is to make a sql query to the selected ids.
 
You'll probably need to use the 'raw' filter type ...

Code:
$myParam = $myInput->get('id_linha','', 'raw');

... as by default it'll use 'text' which I'm pretty sure only allows alphanumeric and - or _, so it'll strip out commas.

Be careful about making sure you sanitize anything you fetch with 'raw' before using in a query.

-- hugh
 
You'll probably need to use the 'raw' filter type ...

Code:
$myParam = $myInput->get('id_linha','', 'raw');

... as by default it'll use 'text' which I'm pretty sure only allows alphanumeric and - or _, so it'll strip out commas.

Be careful about making sure you sanitize anything you fetch with 'raw' before using in a query.

-- hugh

Hi Cheesegrits!

Many thanks for the reply! When we call the variable "id_line", it is already separated by commas: http://prntscr.com/i1likk

But now, with each id that the variable passes, I have to do this query:
$contactoassessor = "SELECT contacto_ctt FROM tb_contacto WHERE id_contacto_geral_ctt IN($myParam) AND tipo_contacto_ctt = 1 ORDER BY date_time DESC LIMIT 1";
$db->setQuery($contactoassessor);
$contacto_assessor = $db->loadResult();
return $contacto_assessor;

The idea is to collect the "contacto_ctt" field of all the ids, and put in a field separated by ";".
I have been to see and there is the function "explode" to separate the ids, the issue is that I will have to use a loop to run all the ids (which the variable has) and I do not know how to do it. Do I really have to use the "explode"? Can the array read be a foreach?

I ask for your help in this situation! I have to deliver the project tomorrow ...
 
The "IN($myParam)" query will return a result set with all the ids, in multiple rows. Use loadColumn() instead of loadResult(), which returns an array of a single columns values from the result set, and implode that ...

Code:
$contacto_assessor = $db->loadColumn();
return implode(';', $contacto_assessor);

-- hugh
 
The "IN($myParam)" query will return a result set with all the ids, in multiple rows. Use loadColumn() instead of loadResult(), which returns an array of a single columns values from the result set, and implode that ...

Code:
$contacto_assessor = $db->loadColumn();
return implode(';', $contacto_assessor);

-- hugh

Hi Cheesegrits!!!

Thank you very much for this help! You are the best!!!
 
The "IN($myParam)" query will return a result set with all the ids, in multiple rows. Use loadColumn() instead of loadResult(), which returns an array of a single columns values from the result set, and implode that ...

Code:
$contacto_assessor = $db->loadColumn();
return implode(';', $contacto_assessor);

-- hugh

Hi Cheesegrits!!!
The "IN($myParam)" query will return a result set with all the ids, in multiple rows. Use loadColumn() instead of loadResult(), which returns an array of a single columns values from the result set, and implode that ...

Code:
$contacto_assessor = $db->loadColumn();
return implode(';', $contacto_assessor);

-- hugh

Hi Cheesegrits!

I thought that this situation was already resolved, but here is a detail that will not let it work!

When I use this query:
$contactoassessor = "SELECT contacto_ctt FROM tb_contacto WHERE id_contacto_geral_ctt IN($myParam) AND tipo_contacto_ctt = 1 ORDER BY date_time DESC";
$db->setQuery($contactoassessor);
$contacto_assessor = $db->loadColumn();
return "'".implode("', '", $contacto_assessor)."'";

I want to populate a field "ids_das_linhas_selecionadas_sms_grp", with the "contact_ctt" of the ids selected! With the format: ( '+351912643315', ) So far so good, it's working!
The question is I have a php script (form pulgin: http://prntscr.com/i24b7p), which will read this field to put in an array:
$numbers = [$formModel->getElementData('tb_envio_sms_grupo___ids_das_linhas_selecionadas_sms_grp')];

But this does not work, because it does not assume as an array but a single value (maybe string).

To test I also tried to put the numbers in variable in the field "ids_das_linhas_selecionadas_sms_grp", and it does not work.
$numeros = "'+351912643315', '+351964650705', '+351939795220'";
return $numeros;

However if you put the numbers in the array directly in plugin form (for testing) it works:
$numbers = ['+351912643315', '+351964650705', '+351939795220'];

I assume that by using the field "ids_das_linhas_selecionadas_sms_grp", the variable "$ numbers" takes on a string.
If you put the numbers directly into the form's pulgin, assume the array.

How can I pass the field value "ids_das_linhas_selecionadas_sms_grp", as array for variable $numbers?
 
The "IN($myParam)" query will return a result set with all the ids, in multiple rows. Use loadColumn() instead of loadResult(), which returns an array of a single columns values from the result set, and implode that ...

Code:
$contacto_assessor = $db->loadColumn();
return implode(';', $contacto_assessor);

-- hugh

Hi Cheesegrits!

I think I have solved the situation! I put the following code:
$numeros_selecionados = $formModel->getElementData('tb_envio_sms_grupo___ids_das_linhas_selecionadas_sms_grp');
$numbers = explode(',', $numeros_selecionados);
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top