We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45189
    • 35 Posts
    Okay so I have a formit form that saves submissions to a custom database table, however all the checkbox/radio fields gets saved into the table as "array" rather than the correct value.

    This is my hook that saves the form to the database, it works:

    $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/mysubmissions/‘;
    $modx->addPackage('mysubmissions',$base_path.'model/');
    $submission_form = $modx->newObject(‘Mysubmissions');
    $submission_form->fromArray($scriptProperties['fields']);
    $submission_form->save();
    return true;


    This is what I am adding above $submission_form->save(); to try and get one of my radio fields to save properly:

    $time_values = $hook->getValue('time_values');
    if (is_array($time_values)){
    	$time_values = implode(',',$time_values);
    	$hook->setValue('time_values', $time_values);
    }


    I have done a ton of Googling and cannot get this to work sad it either still shows up as "array" or just a blank value. Even if I just try hardcoding the value with $hook->setValue('time_values', 'DO SOMETHING'); it doesn't work. This is my HTML for the field i'm testing btw:

    <input type="hidden" name="time_values[]" value="" />
    <input type="radio" name="time_values[]" value="Morning" />
    <input type="radio" name="time_values[]" value="Afternoon" />


    What am I doing wrong??

    This question has been answered by shonna. See the first response.

    • discuss.answer
      • 45189
      • 35 Posts
      Okay, I figured it out. Of course, right after I post this.

      Instead of this:
      $hook->setValue('time_values', $time_values);


      It should have been:
      $submission_form->set('time_values',$time_values);