Book Image

concrete5: Beginner's Guide - Second Edition - Second Edition

Book Image

concrete5: Beginner's Guide - Second Edition - Second Edition

Overview of this book

concrete5 is an open source content management system (CMS) for publishing content on the World Wide Web and intranets. concrete5 is designed for ease of use, and for users with limited technical skills. It enables users to edit site content directly from the page. It provides version management for every page and allows users to edit images through an embedded editor on the page. concrete5 Beginner's Guide shows you everything you need to get your own site up and running in no time. You will then learn how to change the look of it before you find out all you need to add custom functionality to concrete5. concrete5 Beginner's Guide starts with installation, then you customize the look and feel and continue to add your own functionality. After you've installed and configured your own concrete5 site, we'll have a closer look at themes and integrate a simple layout into concrete5. Afterwards, we're going to build a block from scratch which you can use to manage a news section. We're also going to add a button to our site which can be used to create a PDF document on the fly. This book also covers some examples that show you how to integrate an existing jQuery plugin. concrete5 Beginner's Guide is a book for developers looking to get started with concrete5 in order to create great websites and applications.
Table of Contents (19 chapters)
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Pop Quiz Answers
Index

Time for action – adding a check for mandatory fields


Carry out the following steps:

  1. In the previously created file controller.php, add the following method right after the function getBlockTypeName:

    public function getJavaScriptStrings() {
       return array(
          'image-required' => t('You must select an image.')
       );
    }
  2. Create a new file named auto.js in your block directory where you've created controller.php; it will automatically be included when you add or edit a product information block instance. Put the following content in it:

    ccmValidateBlockForm = function() {
       if ($("#ccm-b-image-fm-value").val() == '' || 
           $("#ccm-b-image-fm-value").val() == 0) { 
          ccm_addError(ccm_t('image-required'));
       }
       return false;
    }

What just happened?

We created a JavaScript file, which is automatically included and called before the data is saved.

The method ccmValidateBlockForm is a built-in method, which you can use to interact with the field checking process.

ccm_addError adds an...