Table of Contents

## Creating and Editing Records

To modify records, you need the Professional, Advanced or Enterprise version of phpLens. Using phpLens to generate forms is a productivity boost because

- Input fields are autogenerated for you.
- Must fill fields are autodetected on the browser (using Javascript) and also by the server (when Javascript is disabled on the client).
- The maximum field length and text box width is set for you automatically based on the field size.
- Long text columns are autodetected and displayed as textarea input fields.
- Field validation using Visual Basic style input masks or Javascript regular expressions are supported.
- Popups, check boxes and radio buttons are automatically created based on lookupLens and inputTypeLens settings.
- Image (gif, png, jpeg) display and upload is supported if the field is of type BLOB (MySQL, Oracle) or BYTEA(PostgreSQL).
- Better security as phpLens prevents unauthorized fields from being accessed using a fake input form.
- Template support to separate presentation from logic in Advanced and Enterprise versions.
- High level abstraction of forms makes design and implementation of Web sites faster and easier.

Before phpLens can modify records, it needs to know the name of the table and the primary key of the table it is modifying. The primary key is a number or string that allows you to uniquely identify the record. For example, for a person the primary key could be the driver's license, the social security number or the identity card number. If you are using a simple select statement, phpLens can automatically identify the table. The primary key can be a single field or, since phpLen 2.7, a compound key (multiple fields).

To configure editing from the dynamic editor, click on the phpLens global settings icon. Scroll past the color settings until you see the following:

In the above example, phpLens could not auto-detect the primary key. So you have to enter the primary key from the popup list on the left. Once selected, you can click the following checkboxes:

Then when you are looking on the phpLens grid, you can click on the New or Edit buttons to create or update records. Similarly for deleting records.

Compound Keys

For compound keys, leave the primary key field blank, and enter the list of fields that make up the compound key, delimited by ; in the Compound Key field like this:

keyone;keytwo;keythree

Tips

You can configure the following things when creating records:

How Do I... | Solution | Properties modified
Decide on which fields to display | Click on the green icon to see the New Record Columns. Then move the fields from left to right to display, and right to left to hide. | newLens
Change the field title | Click on the white icon for the field you want to modify and change that field's title. | nameLens
Use a popup instead of a text field | Click on the white icon for the field you want to modify and set the lookup values (options) you want for the popup. | lookupLens
Use a set of radio buttons instead of a text field. | Click on the white icon for the field you want to modify and set the lookup values (options) you want for the popup and click on the Use Radio Buttons setting. New to phpLens 1.2. | lookupLens, inputTypeLens
Have a set of save buttons. Each save button sets a different value for a field. Useful for approval and workflow forms. | Click on the white icon for the field you want to modify and set the lookup values (options) you want for the popup and click on the Use Submit Buttons setting. This will hide the default Save button. New to phpLens 1.2. | lookupLens, inputTypeLens
I do not want the user to be able to cancel | Set the showCancel property to false programmatically. | showCancel
Use a textarea field instead of text input field | Click on the gray icon next to each column to go to the Edit Column screen. Set Input Dimensions, Rows to a value greater than 1. | textSizeLens
Change the textarea or input field dimensions | Click on the gray icon next to each column to go to the Edit Column screen. Set Input Dimensions, Columns and Rows. | textSizeLens
Set default values | Click on the white icon for the field you want to modify and enter the default value. | defaultLens
Prevent users from modifying default values | Click on the green icon to see the New Record Columns screen. From the top of the screen, select from the Choose popup the Read Only Columns option.Then move the fields from left to right to make them read-only, and right to left to make them modifiable. | readOnlyLens
Control the SQL used to insert the data | Requires the Advanced or Enterprise version of phpLens. Configure the spNew property. | spNew
Execute some PHP code before SQL insert is run | Configure the eventPreInsertSQL property programmatically. | eventPreInsertSQL
Execute some PHP code after SQL insert is run | Configure the eventPostInsertSQL property programmatically. | eventPostInsertSQL
Define an input field that phpLens should ignore | Use templates. Requires Advanced or Enterprise version of phpLens. | templateNew
Validate the data | Set the field as a must fill, or define a validation expression. Click on the green icon to see the New Record Columns screen. From the top of the screen, select from the Choose popup the Must Fill Columns option. For more control, a validation expression can be defined as a Visual Basic style input mask or a Javascript regular expression. | mustFill, validation
Use the WYSIWYG HTML editor for a field | Click on the green icon to see the Edit Columns screen. Check WYSIWYG Editor. You do not have to check Do No Convert Special Chars. | htmlEditLens

And these are the settings for editing records:

How Do I... | Solution | Properties modified
Decide on which fields to display | CClick on the green icon to see the Edit Columns screen. Then move the fields from left to right to display, and right to left to hide. | editLens
Change the field title | Click on the white icon for the field you want to modify and change that field's title. | nameLens
Use a popup instead of a text field | Click on the white icon for the field you want to modify and set the lookup values (options) you want in the popup. | lookupLens
Use a textarea field instead of text input field | Click on the gray icon next to each column to go to the Edit Column screen. Set Input Dimensions, Rows to a value greater than 1. | textSizeLens
Change the textarea or input field dimensions | Click on the gray icon next to each column to go to the Edit Column screen. Set Input Dimensions, Columns and Rows. | textSizeLens
Prevent users from modifying visible values | Click on the green icon to see the Edit Columns screen. From the top of the screen, select from the Choose popup the Read Only Columns option. Then move the fields from left to right to make them read-only, and right to left to make them modifiable. | readOnlyLens
Control the SQL used to insert the data | Requires the Advanced or Enterprise version of phpLens. Configure the spEdit property programmatically. | spEdit
Execute some PHP code before SQL update is run | Configure the eventPreUpdateSQL property programmatically. | eventPreUpdateSQL
Execute some PHP code after SQL update is run | Configure the eventPostUpdateSQL property programmatically. | eventPostUpdateSQL
Define a field that phpLens should ignore | Use templates. Requires Advanced or Enterprise version of phpLens. | templateEdit
Validate the data | Set the field as a must fill, or define a validation expression. Click on the green icon to see the Edit Columns screen. From the top of the screen, select from the Choose popup the Must Fill Columns option. For more control, a validation expression can be defined as a Visual Basic style input mask or a Javascript regular expression. | mustFill, validation
Allow image upload | Make sure that the database field is of type BLOB or IMAGE, and that the temporary upload directory property imageTmpDir (which defaults to /tmp) is set correctly. If you do not have read-write access to the /tmp directory, you will also need to modify the $TMP_DIR value in the phplens-img.php file. This file is used to display any images extracted from a database. | imageTmpDir
Selectively define some records to be editable or deletable. | Define two columns in your SQL statement, one called _CANEDIT_ and the other called _CANDELETE_. If the fields are non-zero, then the record is editable or deletable respectively. See the canEdit and canDelete properties for examples. | canEdit, canDelete
Create links to edit and create new records | See our FAQ at http://phplens.com/lens/faq/faq.php?#402 |
Use the WYSIWYG HTML editor for a field | Click on the green icon to see the Edit Columns screen. Check WYSIWYG Editor. You do not have to check Do No Convert Special Chars. | htmlEditLens

### Child Editor in Detail Grid

You can also edit and create records in the detail grid. See the new drop-down list labelled Child Editor in Detail Grid just above the Key Table setting and select one of the settings.For example, have a look at example 320, phplens.com.

### Multiple Record Edit in Grid

Since phpLens 2.0 you can edit multiple records in one grid. This is easy to configure, set:

     $lens->multipleEdit = true;

You can also configure this in a checkbox in phpLens settings. Every field defined in $lens->editLens and $lens->gridLens will be editable in the grid.
Fields that are only defined in $lens->gridLens will be readonly. The detail grid on the right remains read-only.

When you click on the Save button, every row of the grid is treated as a separate SQL insert statement. The phpLens event*SQL properties are called multiple times, once for every row.

#### Performance When Editing in Grid

For good performance, you should cache your popup lists using the cacheLookups property and combine it with the ADODB_CACHE_DIR constant.

    $lens->cacheLookups = 600; // cache for 600 seconds
    define('ADODB_CACHE_DIR','/tmp'); // and store cache in this directory