LiveWhale CMS

Welcome, Guest Login

Support Center

Our documentation is moving:

Please check for the most up-to-date LiveWhale CMS and LiveWhale Calendar documentation. The below legacy documentation will remain available as a reference until the documentation migration is complete.

Custom Form Validation with onFormsSubmission

Last Updated: Nov 25, 2015 10:43AM PST

LiveWhale will automatically validate form fields against expected values, e.g. that a successful form submission requires that an email field receive either a single email address or a series of comma-separated email addresses. LiveWhale also automatically enforces that required field are not empty ('').

If you are adding custom fields to an existing data module, or simply want to enforce additional checks on existing fields, then you can accomplish this with a custom module that utilizes an onFormsSubmission handler. An example module is below.


       'title'=>'My App',

    class LiveWhaleApplicationMyApp {

     // perform additional form validations
      public function onFormsSubmission($id) { 
            global $_LW;
            // use the $id to only apply this validation to a certain form, or perhaps
            // track the presence of a field name in $_LW->_POST
            if ($id === 6) {
                  // sanitized field values are available in $_LW->_POST, which is recommended
                  // all the field name are abstracted, but consistent, so you’ll have to pick
                   // them out.   for example, require that the title is not too long
                  if (strlen($_LW->_POST['lw_form_6_###############']) > 60) {
                        die(json_encode(array('error' => 'Brevity is the soul of wit. (Shakespeare) 
                                     Please  shorten your title to  less than 60 characters.')));
                  // and don’t forget about summary length
                  if (strlen($_LW->_POST['lw_form_6_###############']) > 300) {
                        die(json_encode(array('error' => 'Brevity makes sweetness, doesn't it?
                                 (Stephen King) Please shorten  your summary to less than 300 characters.')));
                  // validations succeeded
            // no validations needed


Expertise Needed: Developer

Software: LiveWhale CMS, LiveWhale One

Version Applicability: Current

SFTP Access Required? Yes
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
Invalid characters found