Hello, I've got some tricky thing to do here))
So I've got a form which will have a checkbox group. This group will contain values from 2 db tables in the following manner. There is a category table and specs table. Specs table has an id_category field so that each category has a number of specs. The checkbox group will look roughly like this:
To add to that the functionality is when I check the Category it checks/unchecks all associated specs. Which will be done by an external JQuery file. Now in order for this to work I need to be able to pass id's classes to each checkbox input so that the Jquery could manipulate them. In general the category gonna have an id like master5 and its specs should have class slave5.
So the question is how do I accomplish that? Maybe using DB Multi Record Loader Associated to another one, but still how do I add id's and classes? Or should I use php to generate the code, if yes please give me an example that is compatible with Chronoforms.
Thanks
So I've got a form which will have a checkbox group. This group will contain values from 2 db tables in the following manner. There is a category table and specs table. Specs table has an id_category field so that each category has a number of specs. The checkbox group will look roughly like this:
Category1
spec1
spec2
spec3
Category2
spec1
spec2
...
To add to that the functionality is when I check the Category it checks/unchecks all associated specs. Which will be done by an external JQuery file. Now in order for this to work I need to be able to pass id's classes to each checkbox input so that the Jquery could manipulate them. In general the category gonna have an id like master5 and its specs should have class slave5.
So the question is how do I accomplish that? Maybe using DB Multi Record Loader Associated to another one, but still how do I add id's and classes? Or should I use php to generate the code, if yes please give me an example that is compatible with Chronoforms.
Thanks
Hi SubCon,
Is this one checkbox group? Or one group for each category?
I'd probably do it using PHP in a Custom Code action to get the data and a Custom Element element to create the HTML.
For the HTML structure you can either use the 'wrapping' capability of the Custom Element element (leave the Pure Code box unchecked), or you could copy the ChronoForms HTML structure from a little dummy form with just a checkbox group.
Bob
Is this one checkbox group? Or one group for each category?
I'd probably do it using PHP in a Custom Code action to get the data and a Custom Element element to create the HTML.
For the HTML structure you can either use the 'wrapping' capability of the Custom Element element (leave the Pure Code box unchecked), or you could copy the ChronoForms HTML structure from a little dummy form with just a checkbox group.
Bob
Its 1 checkbox group. I found the php code it the form code view so I'll use it as an example and make a custom code element that will generate what I need. I hope it the right way to do it.
Here is the code for the custom element that works for me:
Of course I got 2 DB Multi Record Loaders to get the info from the DB.
I do have some question though:
1. whats this piece of code for?
Thanks
<input type="hidden" name="input_checkbox_group_14" value="" alt="ghost" />
<div style="" class="checks_div">
<?php
$options_data = $form->get_array_value($form->data, explode(".", "job-categ")); //Get Job Categories Array
$arr = array();
$options_data2 = $form->get_array_value($form->data, explode(".", "job-specs")); //Get Job Specs Array
if(!is_null($options_data2) && is_array($options_data2)){
$key = 0;
foreach($options_data2 as $option_data2){
if(isset($option_data2["id"]) && isset($option_data2["specialization"])){
$catget = $option_data2["id_category"];
if($catget != $catid){ $catid = $catget; }
$arr[$catid][$key] = array("id" => $option_data2["id"], "specialization" => $option_data2["specialization"]);//new array id_category as key (multidimentional)
$key++;
}
}
}
if(!is_null($options_data) && is_array($options_data)){
$f_id = 0;
foreach($options_data as $option_data){
if(isset($option_data["id"]) && isset($option_data["category"])){
echo '<input type="checkbox" name="input_checkbox_group_15[]" id="input_checkbox_group_15_'.$f_id.'" title="" value="'.$option_data["id"].'"'.
(in_array($option_data["id"], array (0 => '',)) ? ' checked="checked"' : '').' class="validate[\'group[15]\'] master'.$f_id.'" />'."\n";
echo '<label for="input_checkbox_group_15_'.$f_id.'"><b>'.$option_data["category"].'</b></label>'."\n";
if(!is_null($arr[$option_data["id"]]) && is_array($arr[$option_data["id"]])){
$s_id = 0;
echo '<div class="slaves">';
foreach($arr[$option_data["id"]] as $single){
if(isset($single["id"]) && isset($single["specialization"])){
echo '<input type="checkbox" name="input_checkbox_group_15[]" id="input_checkbox_group_15_'.$f_id.$s_id.'" title="" value="'.$single["id"].'"'.
(in_array($single["id"], array (0 => '',)) ? ' checked="checked"' : '').' class="validate[\'group[15]\'] slave'.$f_id.'" />'."\n";
echo '<label for="input_checkbox_group_15_'.$f_id.$s_id.'">'.$single["specialization"].'</label>'."\n";
$s_id++;
}
}
echo '<div class="clear"></div></div>';
}
$f_id++;
}
}
}
?>
</div>
Of course I got 2 DB Multi Record Loaders to get the info from the DB.
I do have some question though:
1. whats this piece of code for?
(in_array($option_data["id"], array (0 => '',)) ? ' checked="checked"' : '').'
Thanks
Hi SubCon,
I think that the odd bit of code is setting the option checked when the id is empty (though why it needs to do that I don't know).
Bob
I think that the odd bit of code is setting the option checked when the id is empty (though why it needs to do that I don't know).
Bob
lol this line is generated automatically if checkboxes field added through the wizard, so I guessed You should know what its there for..
I have another question though: The email sends the checked checkboxes as comma separated string, box1, box2, box2... I'd like for them to appear each in new line. How do I manipulate this field after the send button was hit?
I tried something like this inside email template:
But nothing happens..
I have another question though: The email sends the checked checkboxes as comma separated string, box1, box2, box2... I'd like for them to appear each in new line. How do I manipulate this field after the send button was hit?
I tried something like this inside email template:
<?php
$checkos = "{input_checkbox_group_15}";
$checkos = explode(",", $checkos);
$checkos = implode("<br />", $checkos);
echo $checkos;
?>
But nothing happens..
Hi SubCon,
Max writes the code not me - usually I can understand it but not always :-(
Use the Handle Arrays action to convert the array to a string and use <br /> as the separator should work OK.
Bob
Max writes the code not me - usually I can understand it but not always :-(
Use the Handle Arrays action to convert the array to a string and use <br /> as the separator should work OK.
Bob
Hello Bob
What code to write there?
If I have a checkbox group, the values in the email look like this:
aaa,bbb,ccc
(there is a space missing between each anyway)
But I need
aaa
bbb
ccc
Any idea?
Even better would be if the separator can be set up in the form configuration. 🙂
Thanks!
Patrick
Use the Handle Arrays action to convert the array to a string and use <br /> as the separator should work OK.
What code to write there?
If I have a checkbox group, the values in the email look like this:
aaa,bbb,ccc
(there is a space missing between each anyway)
But I need
aaa
bbb
ccc
Any idea?
Even better would be if the separator can be set up in the form configuration. 🙂
Thanks!
Patrick
Hi Pat01,
Have you tried this?
Bob
Have you tried this?
Use the Handle Arrays action to convert the array to a string and use <br /> as the separator should work OK.
The option you need in the Handle Arrays action is called Delimiter.Bob
This topic is locked and no more replies can be posted.