public $serialized_fields

edited September 2015 in Modules
I'm have a repeating form template that's not saving, it saves '0' to the database field.

my model looks like this:

public $serialized_fields = array('inputs');

public function form_fields($values = array(), $related = array()) {

$fields['inputs'] = array(
'order' => 201,
'display_label' => FALSE,
'type' => 'template',
'fields' => array(
'title' => array('required' => TRUE, 'comment' => 'The input field name (not to be confused with the field label).'),
'body' => array('type' => 'text', 'comment' => 'If left blank, one will be added for you based on the above name value.'),
'gallery' => array('type' => 'checkbox'),
'images' => array('type' => 'template', 'repeatable' => TRUE, 'limit' => 3, 'fields' =>
array('title' => array(),
'image' => array('type' => 'asset', 'multiple' => TRUE),
)
),
),
'class' => 'repeatable',
'add_extra' => FALSE,
'repeatable' => TRUE,
'value' => array(
array('title' => '', 'label' => 'title', 'field' => array('block_name' => 'text'), 'required' => 1),
),
);
return $fields;
}

Before I write my own function I'd like to leverage the framework.

Any idea's as to why it's not working as expected?

Comments

  • edited 5:23AM
    doh, sorted this out. the code works, the database field was set to int. Muppet
  • edited 5:23AM
    having said it works, I get the following errors on saving.

    A PHP Error was encountered
    Severity: Notice

    Message: Array to string conversion

    Filename: helpers/MY_language_helper.php

    Line Number: 72

    A PHP Error was encountered
    Severity: Warning

    Message: Cannot modify header information - headers already sent by (output started at /users/david/Sites/astonmartin/fuel/codeigniter/core/Exceptions.php:186)

    Filename: libraries/Session.php

    Line Number: 689

    A PHP Error was encountered
    Severity: Warning

    Message: Cannot modify header information - headers already sent by (output started at /users/david/Sites/astonmartin/fuel/codeigniter/core/Exceptions.php:186)

    Filename: helpers/MY_url_helper.php

    Line Number: 399
  • edited 5:23AM
    A couple questions:
    1. What version of FUEL are you running (you can check the fuel/modules/fuel/config/fuel_constants.php file)?
    2. What does line 72 of the MY_language_helper.php file look like for you an what is the array value that it's trying to convert?
  • edited 5:23AM
    define('FUEL_VERSION', '1.3.1');

    regarding MY_language_helper.php, it's line 65 (I had some debug code it)

    return call_user_func_array('sprintf', $args);
  • edited 5:23AM
    Was it your debug code that was causing that error in My_language_helper.php or is there still an error in that file and if so, what is the value of $args?
  • edited 5:23AM
    it wasn't my debug causing the issue, the errors occur on edit and save. the args are

    array (
    0 => false,
    )..........
    array (
    0 => 'Dashboard',
    )
    array (
    0 => 'Pages',
    )
    array (
    0 => 'Blocks',
    )
    array (
    0 => 'Navigation',
    )
    array (
    0 => 'Tags',
    )
    array (
    0 => 'Categories',
    )
    array (
    0 => 'Assets',
    )
    array (
    0 => 'Site Variables',
    )
    array (
    0 => 'Users',
    )
    array (
    0 => 'Permissions',
    )
    array (
    0 => 'Page Cache',
    )
    array (
    0 => 'Activity Log',
    )
    array (
    0 => 'Settings',
    )
    array (
    0 => 'Here you can manage the data associated with the page.',
    )
    array (
    0 => 'Upload',
    )
    array (
    0 => 'Upload',
    )
    array (
    0 => 'Layout',
    )
    array (
    0 => 'Published',
    )
    array (
    0 => 'Upload',
    )
    array (
    0 => 'Upload',
    )
    array (
    0 => 'Here you create and edit the top menu items of the page.',
    )
    array (
    0 => 'Navigation Group:',
    )
    array (
    0 => 'Upload',
    )
    array (
    0 => 'Download',
    )
    array (
    0 => false,
    )
    array (
    0 => 'Here you can upload new assets. Select overwrite if you would like to overwrite a file with the same name.',
    )
    array (
    0 => 'Asset folder',
    )
    array (
    0 => 'Upload',
    )
    array (
    0 => 'Here you can manage the site variables for your website.',
    )
    array (
    0 => 'Here you can manage the data for users.',
    )
    array (
    0 => 'Here you can manage the permissions for FUEL modules and later assign them to users.',
    )
    array (
    0 => 'Here you can manage the permissions for FUEL modules and later assign them to users.',
    )
    array (
    0 => 'Select one...',
    )
    array (
    0 => 'Select one...',
    )
    array (
    0 => 'Select one...',
    )
    array (
    0 => 'Here you can manage the %1s for your site.',
    1 => 'social icons',
    )
    array (
    0 => 'FUEL CMS',
    )
    array (
    0 => 'Search...',
    )
    array (
    0 => 'Save',
    )
    array (
    0 => 'Cancel',
    )
    array (
    0 => 'Add',
    )
    array (
    0 => 'Edit',
    )
    array (
    0 => 'Select',
    )
    array (
    0 => 'Asset',
    )
    array (
    0 => 'Image',
    )
    array (
    0 => 'PDF',
    )
    array (
    0 => 'Flash',
    )
    array (
    0 => 'Upload Asset',
    )
    array (
    0 => 'Source',
    )
    array (
    0 => 'Editor',
    )
    array (
    0 => 'Preview',
    )
    array (
    0 => 'Select All',
    )
    array (
    0 => 'Deselect All',
    )
    array (
    0 => 'There are no more values to select',
    )
    array (
    0 => 'Select from the values on the left',
    )
    array (
    0 => 'Filter your search',
    )
    array (
    0 => '_orphans',
    )
    array (
    0 => 'Are you sure you want to delete this?',
    )
    array (
    0 => 'Send password update email notification?',
    )
    array (
    0 => 'Error importing view file',
    )
    array (
    0 => 'Close',
    )
    array (
    0 => 'New Window',
    )
    array (
    0 => 'You can change the precedence order by selecting and dragging the data rows below.',
    )
    array (
    0 => 'Are you sure you want to replace the contents of this record?',
    )
    array (
    0 => 'You must have only have one option selected to edit.',
    )
    array (
    0 => '⇡ Close',
    )
    array (
    0 => '⇣ Open',
    )
    array (
    0 => 'Bold',
    )
    array (
    0 => 'Italic',
    )
    array (
    0 => 'Stroke Through',
    )
    array (
    0 => 'Paragraph',
    )
    array (
    0 => 'Heading 1',
    )
    array (
    0 => 'Heading 2',
    )
    array (
    0 => 'Heading 3',
    )
    array (
    0 => 'Heading 4',
    )
    array (
    0 => 'Bullet List',
    )
    array (
    0 => 'Numeric List',
    )
    array (
    0 => 'List Item',
    )
    array (
    0 => 'Block Quote',
    )
    array (
    0 => 'Horizontal Rule',
    )
    array (
    0 => 'Image',
    )
    array (
    0 => 'Link',
    )
    array (
    0 => 'Target',
    )
    array (
    0 => 'Title',
    )
    array (
    0 => 'Mailto',
    )
    array (
    0 => 'PHP Variable',
    )
    array (
    0 => 'Clean',
    )
    array (
    0 => 'Preview Toggle (hold down alt/option and click to preview)',
    )
    array (
    0 => 'Full Screen',
    )
    array (
    0 => 'Your title here...',
    )
    array (
    0 => 'Your text to link...',
    )
    array (
    0 => 'email@address.com',
    )
    array (
    0 => 'Close',
    )
    array (
    0 => 'Are you sure you want to delete this item?',
    )
    array (
    0 => 'Add Another',
    )
    array (
    0 => 'Remove',
    )
    array (
    0 => 'Click "Save" to use this file.',
    )
    array (
    0 => 'Here you can manage the %1s for your site.',
    1 => 'models page',
    )
    array (
    0 => 'Create',
    )
    array (
    0 => false,
    )
    array (
    0 => 'required fields',
    )
    array (
    0 => 'yes',
    )
    array (
    0 => 'no',
    )
    array (
    0 => 'Precedence',
    )
    array (
    0 => false,
    )
    array (
    0 => 'Title',
    )
    array (
    0 => false,
    )
    array (
    0 => false,
    )
    array (
    0 => false,
    )
    array (
    0 => 'Title',
    )
    array (
    0 => 'Image',
    )
    array (
    0 => 'Double click to open',
    )
    array (
    0 => 'Title',
    )
    array (
    0 => 'Image',
    )
    array (
    0 => 'Double click to open',
    )
    array (
    0 => 'Double click to open',
    )
    array (
    0 => 'Active',
    )
    array (
    0 => false,
    )
    array (
    0 => false,
    )
    array (
    0 => 'Value needs to be a number for %1s.',
    1 => '\'id\'',
    )
    array (
    0 => 'Value exceeds required length for %1s.',
    1 => '\'id\'',
    )
    array (
    0 => 'Value needs to be a number for %1s.',
    1 => '\'model id\'',
    )
    array (
    0 => 'Value exceeds required length for %1s.',
    1 => '\'model id\'',
    )
    array (
    0 => 'Value needs to be a number for %1s.',
    1 => '\'precedence\'',
    )
    array (
    0 => 'Value exceeds required length for %1s.',
    1 => '\'precedence\'',
    )
    array (
    0 => 'Invalid value for %1s',
    1 => '\'active\'',
    )
    array (
    0 => '%1s item %2s edited',
    1 => 'Models Page',
    2 =>
    array (
    0 =>
    array (
    'title' => 'test title',
    'body' => 'Quisque velit nisi, pretium ut lacinia in, elementum id enim. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Curabitur aliquet quam id dui posuere blandit. Pellentesque in ipsum id orci porta dapibus. Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec velit neque, auctor sit amet aliquam vel, ullamcorper sit amet ligula. Donec rutrum congue leo eget malesuada. Vivamus suscipit tortor eget felis porttitor volutpat. Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui.',
    'images' =>
    array (
    0 =>
    array (
    'title' => '',
    'image' => '',
    ),
    ),
    ),
    ),
    )
    array (
    0 => 'Value needs to be a number for %1s.',
    1 => '\'user id\'',
    )
    array (
    0 => 'Value exceeds required length for %1s.',
    1 => '\'user id\'',
    )
    array (
    0 => 'Value exceeds required length for %1s.',
    1 => '\'type\'',
    )
    array (
    0 => 'Data has been saved.',
    )
  • edited 5:23AM
    Would you mind posting the minimal code for your model and SQL to replicate your issue. I'm having a hard time replicating the issue given the current information. Thanks.
  • edited 5:23AM
    here you go, the db table

    CREATE TABLE `model_pages` (
    `id` int(11) NOT NULL,
    `model_id` int(11) NOT NULL,
    `inputs` text NOT NULL,
    `precedence` int(11) NOT NULL DEFAULT '3',
    `active` enum('yes','no') NOT NULL DEFAULT 'yes'
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    ALTER TABLE `model_pages`
    MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

    and the model:

    class Models_page_model extends Base_module_model {

    public $serialized_fields = array('inputs');

    public function form_fields($values = array(), $related = array()) {

    $fields = parent::form_fields($values, $related);

    $fields['inputs'] = array(
    'order' => 201,
    'display_label' => FALSE,
    'type' => 'template',
    'title_field' => 'title',
    'fields' => array(
    'section' => array('type' => 'section', 'value' => '__title__'),
    'title' => array('required' => TRUE, 'comment' => 'The input field name (not to be confused with the field label).'),
    'body' => array('type' => 'text', 'comment' => 'If left blank, one will be added for you based on the above name value.'),
    'gallery' => array('type' => 'checkbox'),
    'images' => array('type' => 'template', 'repeatable' => TRUE, 'limit' => 12, 'fields' =>
    array('title' => array(),
    'image' => array('type' => 'asset', 'multiple' => TRUE),
    )
    ),
    ),
    'class' => 'repeatable',
    'add_extra' => FALSE,
    'repeatable' => TRUE,
    'value' => array(
    array('name' => 'title', 'label' => 'Title', 'field' => array('block_name' => 'text'), 'required' => 1),
    ),
    );

    return $fields;

    }


    cheers
  • edited 5:23AM
    I see the issue. It is because you don't have a "display_field" specified in MY_fuel_modules config for your module is my guess and it is by default picking the first non-id field from the table automatically for the "display_field" parameter. This is your input field which returns an array of data. If you setup a field before input like "name", it will use that instead. I've posted a fix though in the develop branch which will encode any array value to JSON... it will look ugly in the top breadcrumb area (that's where the display_field value is used), but it will prevent the error.
    https://github.com/daylightstudio/FUEL-CMS/commit/984e09a024bdbcfa00c7614c5183ca9feab184b2
Sign In or Register to comment.