phpLens
 home  products examples manual  faq support forum  contact news  login store

More Examples:   View Source:   Creating, Editing and Deleting Demo

Free Download

This example script demonstrates Javascript validation when creating or editing records. To try it, click on the New record button in the applet below.

If the firstname is filled, then we validate that the lastname is also filled. If the firstname is empty, then we do not validate the lastname.

First we setup the following property:

$lens->validation = 'FIRSTNAME^%validatename( )^';

Then we define the javascript:

<script defer>
// if first name is set, then lastname must be set
function validatename()
{
   if (document.phplens_ex309_edit.lens_FC_FIRSTNAME.value) 
      if (! document.phplens_ex309_edit.lens_FC_LASTNAME.value) {
        alert('Both first and last name must be filled');
        return '';
      }

   return 1;

}
</script>

If the javascript function returns:

  • 0 or false, then the default error message will appear.
  • '' then we hide the default error message, so you can define your own error message.
  • 1 or true, then the data is validated correctly.

    This is a Demo. You can not change anything for security reasons.
    Back to Grid     phpLens Settings   Choose   Generate PHP Code   Remove All Settings   ?  
     
    IndexColumn NameActual TypePHPLens Type
    1USERID string[16]C: Character
    2PASSWORD string[16]C: Character
    3FIRSTNAME string[24]C: Character
    4LASTNAME string[24]C: Character
    5EMAIL string[48]C: Character
    6ADDRESS1 string[48]C: Character
    7ADDRESS2 string[48]C: Character
    8POSTCODE string[12]C: Character
    9CITY string[24]C: Character
    10STATE string[24]C: Character
    11COUNTRY string[24]C: Character
    12AGE int[11]I: Integer
    13CREATED datetime[19]T: Timestamp
    14LASTMOD datetime[19]T: Timestamp
     

    Notes

    When editing or creating new records, userid and password are set as must fill fields. Age only accepts numbers (this is automatic, no programming required), and email addresses are validated.

    See Example 302 and Example 303 which uses the same data.

    Table schema

      create table lensusers (
          USERID char(16) not null,
        PASSWORD char(16) not null,
          FIRSTNAME char(24) ,
        LASTNAME char(24) not null,
        EMAIL char(48) not null,
        ADDRESS1 char(48) not null,
        ADDRESS2 char(48) ,
        POSTCODE char(12) ,
        CITY char(24) ,
        STATE char(24) ,
        COUNTRY char(24) not null,
        AGE integer,
        CREATED datetime not null,
        LASTMOD datetime not null,
        primary key (userid)
      );
      

    This demo also shows you Google style scrolling. In this case, this is enabled by setting

      $lens->scrollLinks = 9
      

    which sets the number of scrolling links to 9.

    sameRowLens

    Also notice that the fields FirstName/LastName and PostCode/City are on the same line in the Details Grid, and New/Edit record forms. This is configured by checking "2 Fields in 1 Row" in the column settings for PostCode.

    sectionLens

    We also have section breaks with "Misc" and "Address" using the sectionLens property.

email: info#phplens.com (change # to @)     telephone (malaysia): 60-3 7806 1216     fax (malaysia): 60-3 7806 1210