I have the multi field checkbox element on my form. And have the variable, getting from url.
I want to create the checkbo items with its labels which depend on this variable using custom php or javascript code.
How i can create checkbox item or its label by dynamically?
I want to create the checkbo items with its labels which depend on this variable using custom php or javascript code.
How i can create checkbox item or its label by dynamically?
It is my massive i want use for checkbox items creation:
where "dd11" and "dd12" are variables from url
$chbitems = array (
"dd11" => array (
'chbvalue11' => 'some text 11',
'chbvalue12' => 'some text 12'
),
"dd12" => array (
'chbvalue11' => 'some text 11',
'chbvalue12' => 'some text 12',
'chbvalue13' => 'some text 13'
)
);
where "dd11" and "dd12" are variables from url
Hi s.elena133,
You have to add a little code to change the structure of the data - assuming that the parameter name is param:
Bob
You have to add a little code to change the structure of the data - assuming that the parameter name is param:
<?php
$chbitems = array (
"dd11" => array (
'chbvalue11' => 'some text 11',
'chbvalue12' => 'some text 12'
),
"dd12" => array (
'chbvalue11' => 'some text 11',
'chbvalue12' => 'some text 12',
'chbvalue13' => 'some text 13'
)
);
$form->data['boxes'] = array();
foreach ( $chbitems[$form->data['param']] as $k => $v ) {
$boxes[] = array('value' => $k, 'text' => $v);
}
?>
Then you should be able to use the Dynamic Data tab of the CheckBox group action with:
Data Path : boxes
Value key : value
Text key : text
Bob
Hi Bob,
I did, but can't see the result
Got the error "Warning: array_combine() expects parameter 1 to be array, null given in..." with the string:
Now my code is:
I did, but can't see the result
Got the error "Warning: array_combine() expects parameter 1 to be array, null given in..." with the string:
for each ( $chbitems[$param] as $k => $v ) {
Now my code is:
$param = $_GET['dd1']; // = "dd11" or "dd12"
$form->data['boxes'] = array();
for each ($chbitems[$param] as $k => $v ) {
$boxes[] = array('value' => $k, 'text' => $v);
}
Hi s.elena133,
Please replace for each with foreach (no space) - sorry about that. If that doesn't fix the problem please post the full error message here.
Bob
Please replace for each with foreach (no space) - sorry about that. If that doesn't fix the problem please post the full error message here.
Bob
Hi, Bob
Many thanks for your answers.
It is not your mistake. I was very inattentive by myself. When I did, the error is gone. But the main problem lies elsewhere.
When i enable the dynamic data (tab "dynamic data" for my checkbox group ) the other error is appear:
"Warning: array_combine() expects parameter 1 to be array, null given in Z:\home\site-selena\www\administrator\components\com_chronoforms5\chronoforms\actions\html\html.php(263) : eval()'d code on line 27"
If i disable this option this error is disappearing.
Many thanks for your answers.
It is not your mistake. I was very inattentive by myself. When I did, the error is gone. But the main problem lies elsewhere.
When i enable the dynamic data (tab "dynamic data" for my checkbox group ) the other error is appear:
"Warning: array_combine() expects parameter 1 to be array, null given in Z:\home\site-selena\www\administrator\components\com_chronoforms5\chronoforms\actions\html\html.php(263) : eval()'d code on line 27"
If i disable this option this error is disappearing.
Hi s.elena133,
As far as I can see that line in the html.php file is evaluating the main form content. Please can you check the Code tab and see what there is around line 27.
Note that this is just a PHP Notice and is annoying but harmless. Setting the site Error Reporting to System Default or to None should hide it.
Bob
As far as I can see that line in the html.php file is evaluating the main form content. Please can you check the Code tab and see what there is around line 27.
Note that this is just a PHP Notice and is annoying but harmless. Setting the site Error Reporting to System Default or to None should hide it.
Bob
Hi Bob,
Now i have code:
My code editor does not see any sintax errors.
Now i have code:
<?php
$chbitems = array (
"dd11" => array (
'chbvalue11' => 'some text 11',
'chbvalue12' => 'some text 12'
),
"dd12" => array (
'chbvalue11' => 'some text 11',
'chbvalue12' => 'some text 12',
'chbvalue13' => 'some text 13'
)
);
$param = $_GET['dd1']; // = "dd11" or "dd12" // 26
// it is my 27 string
$form->data['boxes'] = array(); // 28
foreach ($chbitems[$param] as $k => $v ) {
$boxes[] = array('value' => $k, 'text' => $v);
echo '$chbitems key = '.$k.' value = '.$v; // This string is working and print the right information
}
?>
My code editor does not see any sintax errors.
Oh, sorry
I forgot, on dynamic data tab of my checkbox group are options:
Enable dynamic data: Yes
Data path: boxes
Key value: value
Text key: text
I forgot, on dynamic data tab of my checkbox group are options:
Enable dynamic data: Yes
Data path: boxes
Key value: value
Text key: text
Maybe without 'dynamic data'.
Using some code like:
But i don't know about 'options', what the name of this input's variable and how correct this code
Using some code like:
$count = 0;
foreach ($chbitems[$param] as $k => $v ) {
$form->data['boxes']['options'][$count] = array('value' => $k, 'text' => $v);
$count++;
}
But i don't know about 'options', what the name of this input's variable and how correct this code
Hi s.elena133,
I do not see an array_combine() function anywhere in that piece of code?
Bob
I do not see an array_combine() function anywhere in that piece of code?
Bob
Hi Bob,
I'm too.
It can be such an array with "Key value: value" and "Text key: text" (from dynamic data tab)? And my massive is not correctly for it ("1 parametr, but null given")
Error appear when i enable "dynamic data" and disappear when i disable it (but code does not work too, of course)
I'm too.
It can be such an array with "Key value: value" and "Text key: text" (from dynamic data tab)? And my massive is not correctly for it ("1 parametr, but null given")
Error appear when i enable "dynamic data" and disappear when i disable it (but code does not work too, of course)
Hi s.elena123,
The message says "Warning: array_combine() expects parameter 1 to be array, . . ." So there should be an array_combine() function call in the code somewhere.
By all means PM me the site URL, the form name, and a SuperAdmin login and I'll take a quick look.
Bob
The message says "Warning: array_combine() expects parameter 1 to be array, . . ." So there should be an array_combine() function call in the code somewhere.
By all means PM me the site URL, the form name, and a SuperAdmin login and I'll take a quick look.
Bob
This topic is locked and no more replies can be posted.