0

I have the following in the form.php:

$color->output('color', $color, array('showAlpha' => 'false'));

echo $form->select('font', $fonts, $font_selected);

and controller.php:

edit(){
$this->set('font', $font); // $font - user selected font
$this->set('fonts', $fonts); // $fonts - array of available fonts
$this->set('color', 'rgb(0, 0, 0)');
}
save() {
$args['color'] = isset($args['color']) ? trim($args['color']) : 'rgb(0, 0, 0)';
$args['font'] = isset($args['font']) ? trim($args['font']) : '';
}
  1. How can I pass color to the form widget? With $color in there, it fails to open the form (must be throwing an uncaught exception). If I change $color to '', the form opens, but the color is obviously not set.
  2. How can I save the selected font value, not the index? The $args['font'] saves the selected index only, not the option text value.

Thank you.

linuxoid
  • 1,415
  • 3
  • 14
  • 32
  • Ok, I've figured out how to get the color widget to accept a color value from the controller (the 2 $color variables might have had a conflict + the preferredFormat setting): $ch = Core::make('helper/form/color'); $ch->output('color', $color ? $color : '#0099ff', array('showAlpha' => 'false', 'preferredFormat' => 'hex')); – linuxoid May 08 '18 at 13:42
  • I also found half of the problem - I forgot the 'this' for the variable taken from the DB: changed $this->set('font', $font); to $this->set('font', $this->font); and it works just fine! However the problem remains - it's the select index which gets stored in $args['font'], I still need the actual text for that index to store in the DB. – linuxoid May 08 '18 at 13:42
  • if I do this: $args['font'] = array_keys($this->fonts)[1]; or simply this: $args['font'] = $this->fonts[1]; - it saves nothing! How come? array_keys($this->fonts)[1] shows up in the view just fine – linuxoid May 08 '18 at 14:42

0 Answers0