Form Field Types : multi

rl2rl2
edited October 2017 in Share
Hello,

I've created the following in my model:

$tags = array('bike' => 'bike', 'breakdown' => 'breakdown', 'business' => 'business', 'car' => 'car', 'home' => 'home', 'other'
=> 'other', 'pet' => 'pet', 'travel' => 'travel', 'van' => 'van');
$fields['tags'] = array( 'type' => 'multi', 'mode' => 'multi', 'options' => $tags);

In my database I have a 'tags' column name, but firstly I don't know what Data Type the field should be?

When saving the record I get the following error:

Message: Array to string conversion

And further down the culprit:

Error Number: 1054

Unknown column 'Array' in 'field list'

INSERT IGNORE INTO `kbarticles` (`id`, `title`, `tags`, `slug`, `section1_heading`, `section1_content`, `section1_image`, `section2_heading`, `section2_content`, `section2_image`, `section3_heading`, `section3_content`, `section3_image`, `section4_heading`, `section4_content`, `section4_image`, `section5_heading`, `section5_content`, `section5_image`, `published`) VALUES ('3', 'What are the different types of Insurance cover?', Array, '/test', 'Explore the different types of coverage', '

Comments

  • rl2rl2
    edited 7:32AM
    Okay, I've serialized the field that seems to provide a working solution; so the chosen options are saved as JSON.
  • rl2rl2
    edited 7:32AM
    However, if tag(s) are saved and then removed fully and resaved it doesn't recognise the user emptied the field. Hmmm.
  • rl2rl2
    edited October 2017
    function on_before_save($values) {
    if ( sizeof( $values['tags'] ) == 0 ) {
    $values['tags'] = '';
    }
    return $values;
    }
Sign In or Register to comment.