Required field

edited November 2016 in News & Announcements
I've created a block_layout and specified one required field, but the block will save irrespective of whether anything is in in the field.

Do I need to do something else to get it to vaidate?

$event_hero_image = new Fuel_block_layout('hero_image'); $event_hero_image->add_field('title', array()); $event_hero_image->add_field('image', array('type' => 'asset', 'multiple' => FALSE, 'required' => TRUE)); $event_hero_image->add_field('link', array()); $config['blocks']['hero_image'] = $event_hero_image;

Comments

  • edited 4:36AM
    Block layouts require some additional validation to work. There is a "validate" method you can leverage that gets passed all the page variables. The default Fuel_block_layout object that you are using simply returns true though. So to get it to work, Create a class that extends Fuel_block_layout and implement the "validate" method. You can use $this->_add_error('My Error message'); to register an error for the layout which will get picked up on the front and and displayed.

    More on extending the Fuel_layout classes here:
    http://docs.getfuelcms.com/general/layouts
Sign In or Register to comment.