Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » Retrieving data out of Check Boxes - Groups

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 355 Views
  • SeanBoy
    Avatar
    Community Member
    8 Posts

    Retrieving data out of Check Boxes - Groups Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Retrieving data out of Check Boxes - Groups Link to this post

    Do a var_dump($data); or a

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


    to see what gets posted

  • SeanBoy
    Avatar
    Community Member
    8 Posts

    Re: Retrieving data out of Check Boxes - Groups Link to this post

    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.

    355 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.