Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions

Retrieving data out of Check Boxes - Groups


Reply

3 Posts   379 Views

Avatar
SeanBoy

15 February 2012 at 11:54am (Last edited: 15 February 2012 11:57am), Community Member, 8 Posts

Hi

I have created a form using the form module. This contains a Checkbox group I am now trying to extract the values from each of the check boxes in that group. Can anyone point me in the direction of a tutorial or example or explain how I could do this?

For information, I am doing this in the forms controller class, within the process function. I normally get the values out of fields by doing the following:

function process($data, $form) {
$this->weekType = $data["EditableDropdown42"];
// Run through form to get the job type
foreach ($this->Fields() as $field) {
switch ($field->Name) {
case "EditableDropdown3":
$this->runJob($data[$field->Name]);
break;
}
}

Can anyone help please?

Thanks in advance, Sean

Avatar
martimiz

16 February 2012 at 1:25am (Last edited: 16 February 2012 1:26am), Forum Moderator, 1091 Posts

Do a var_dump($data); or a

foreach($data as $key => $value) echo"$key - $value<br />";


to see what gets posted

Avatar
SeanBoy

16 February 2012 at 5:21am (Last edited: 16 February 2012 5:23am), Community Member, 8 Posts

Nearly got it? The dump returns the following :

.....
'EditableCheckboxGroupField14' =>
array
'aaa' => string 'aaa' (length=3)
'ccc' => string 'ccc' (length=3)
.....

where both aaa and ccc are the names of each tick box (that are ticked). However the foreach does not execute so I can't tell whats in the array:

foreach ($data[$field->Name] as $key => $value) {
echo"$key - $value<br />";
}


The code does not even get into this loop.

Any help most appreciated.