Forums

Checkbox group values - can it have a different format to save in db

Jojo 20 Aug, 2015
Hi,


I have installed Chronoform v% component to create a Contact Us form for my site. My Checkbox group e.g, has following values:

Review: Good
Bad
Average

Suppose if any user Checks two items i.e, Bad and Average, the format in which it should save in database should be like:
Review: Good
Bad: Yes
Average: Yes

In short it should display all checkbox values but should display 'Yes' in front of the value selected by user. Is it possible?? Any suggestions?

Thanks
GreyHead 20 Aug, 2015
Hi poojah12,

I'm not sure that it makes sense to use a Checkbox goup like this - Radio buttons are usually used where only one choice is needed.

If you use a Checkbox group then you can use Custom HTML - possibly with a little PHP - to format the output.

Bob
Jojo 21 Aug, 2015
The php should be written in Template email custom format right?
GreyHead 21 Aug, 2015
Hi poojah12,

I would put it in a Custom Code action before the Email action and add the result to the $form->data array so that it can be included in the template.
<?php
$form->data['my_extra html'] = "some text and HTML and {$form->data['form_data']} etc ";
?>
Then you can put {my_extra_html} in the template.

It should also work in the template though.

Bob
Jojo 24 Aug, 2015
Hi GreyHead,

I placed this code in custom code

<?php
$form->data['mesage'] = isset($_POST['Services']) ? 'Yes' : 'No';
?>

Is the format correct? Services is the checkbox group name.
GreyHead 24 Aug, 2015
Hi poojah12,

It's not code that I would use but looks OK. Does it work?

Bob

PS As ChronoForms uses the $form->data[''] array to manage for data it might be better to use $form->data['Services'] but either will work
Jojo 24 Aug, 2015
No its not returning any value. The debugger is on. It says error in Array()
Jojo 24 Aug, 2015
You told that 'It's not code that I would use'...means is there any other way to achieve this output format? Please suggest.

The php code is proper but i am confused with the format how this should be written inside custom html.
GreyHead 24 Aug, 2015
Hi poojah12,

I still don't understand what use a Checkbox group is here :-(

Is the Checkbox Group named 'Services' ? What are the values of individual boxes?

Bob
Jojo 25 Aug, 2015
I know its weird sort of qustion.But its my client's requirement for whom I am redesigning a existing website in which one form has this checkbox group. May be the old site had this output format.

Ya the checkbox group name is Services[]. Following are the values of each of the 8 checkboxes in the group.
1)value="Strategic Planning"
2)value="Organizational Change & Development"
3)value="Balanced Scorecard & Performance Management"
4)value="Assessments & Surveys"
5)value="Quality & TQM"
6)value="Performance appraisal, HR audits"
7)value="Training"
8)value="Other"
Jojo 25 Aug, 2015
Hello GreyHead,

Any suggestions?
GreyHead 26 Aug, 2015
Hi poojah12,

This is a different question? It doesn't seem to have anything to do with the Good, Bad, Maybe question you started with?

I guess I'm just confused about what you need to do here :-(

Bob
Jojo 26 Aug, 2015
I am sorry for the confusion Mr. GreyHead. See i have a question in my form which has following checkboxes for selection.
Please select all Organized Change Consultancy
services of interest:
[list]Strategic Planning[/list]
[list]Organizational Change & Development[/list]
[list]Balanced Scorecard & Performance Management[/list]
[list]Assessments & Surveys[/list]

Now when the user selects for example the first two checkboxes. The format of the output of this question which i receive in my mail is:
Please select all Organized Change Consultancy
services of interest:
Strategic Planning, Organizational Change & Development

But I have a requirement to get the output format like this:
Please select all Organized Change Consultancy
services of interest:
Strategic Planning - Yes
Organizational Change & Development - Yes
Balanced Scorecard & Performance Management -
Assessments & Surveys -


I tried with this code <?php
$form->data['mesage'] = isset($_POST['Services']) ? 'Yes' : 'No';
?> but its not working. And I also tried by giving ckeckbox value as 'Yes' for all but it is not getting accepted.

The checkbox group name is Services[]. Following are the values of each of the 8 checkboxes in the group.
1)value="Strategic Planning"
2)value="Organizational Change & Development"
3)value="Balanced Scorecard & Performance Management"
4)value="Assessments & Surveys"
GreyHead 26 Aug, 2015
Hi poojah12,

Please try something like this in a Custom Code action before the Email action, then add {services_output} in the Email template.
<?php
$services = array(
  'Strategic Planning',
  'Organizational Change & Development',
  'Balanced Scorecard & Performance Management',
  'Assessments & Surveys',
  'Quality & TQM',
  'Performance appraisal, HR audits',
  'Training',
  'Other'
);
$output = array();
foreach ( $services as $s ) {
  $value = 'Yes';
  if ( empty($form->data['Services'][$s]) ) {
    $value = 'No';
  }
  $output[] = "<p>{$s}: {$value}</p>";
}
$form->data['services_output'] = implode("\n", $output);
?>

Bob
Jojo 26 Aug, 2015
Hello GreyHead,

I placed the above code in my Custom Code then in my email template i specified {services_output}. But nothing shows up. My Debugger is on.
GreyHead 26 Aug, 2015
Hi poojah12,

The code looks OK to me so my best guess is that there is a mismatch with the form data. Please remove (or comment out) this code, then submit the form and post the Debugger output here.

Bob
Jojo 27 Aug, 2015
Hi GreyHead,

This is the code i placed in my Custom HTML before
<?php
$Services = array(
  'Strategic Planning',
  'Organizational Change & Development',
  'Balanced Scorecard & Performance Management',
  'Assessments & Surveys',
  'Quality & TQM',
  'Performance appraisal, HR audits',
  'Training',
  'Other'
);
$output = array();
?>


and in my email template i specified {Services_output}

I removed the code as you said. And here is the debugger output:
[code]Data Array
Array
(
[chronoform] => Elearning
[event] => submit
[option] => com_chronoforms5
[Itemid] =>
[firstname] => yuyi
[lastname] => vfdf
[email] => pooja_jojo12@yahoo.com
 => 56
    [phone] => 7666
    [company] => fdd
    [Services] => Organizational Change & Development,Balanced Scorecard & Performance Management
    [other] => 
    [additionalinfo] => dsfs
    [howdidyouhear] => Current/Past_Client
    [register] => Contact Us
    [id] => 18
    [ip_address] => 163.47.12.168
)
Array
(
)

Errors
Array
(
)
Debug Info
Array
(
    [11] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `E_learning_database` (`firstname`, `lastname`, `email`, `code`, `phone`, `company`, `Services`, `other`, `additionalinfo`, `howdidyouhear`, `register`, `user_id`, `uniq_id`, `created`) values ('yuyi', 'vfdf', 'pooja_jojo12@yahoo.com', '56', '7666', 'fdd', 'Organizational Change & Development,Balanced Scorecard & Performance Management', '', 'dsfs', 'Current/Past_Client', 'Contact Us', '0', '1e69f28e76e0655d61e58ec40075576cc6708a21', '2015-08-27 05:06:38');
                        )

                )

        )

    [0] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:pooja.jojo12@gmail.com
                    [2] => Subject:E learning New Record
                    [3] => From name:Organized Change E learning
                    [4] => From email:elearning@safehandindia.com
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Array
                        (
                        )

                    [11] => Body:
GreyHead 27 Aug, 2015
Hi poojah12,

It looks as though you have added a Handle Arrays action that is converting the Services values into a string before the Custom Code runs. The code is expecting an array.
[Services] => Organizational Change & Development,Balanced Scorecard & Performance Management

Bob
Jojo 27 Aug, 2015
No I checked. I have'nt added any Handle Array action.
GreyHead 27 Aug, 2015
Hi poojah12,

Well - that is definitely not an array any more :-( so something is converting it.

Bob
Jojo 27 Aug, 2015
I have named the checkbox group name as Services[]. That correct way right?
Jojo 28 Aug, 2015
Hello GreyHead

I could solve the output issue without using php. I just removed the [] from checkbox group names, gave different names to all of them and gave value of "Yes" to all. Which worked exactly how i wanted. Anyways I am extremely thankful for your support for all my queries. Thanks a lot. This is a great extension for forms.
This topic is locked and no more replies can be posted.