How to add a button to a form

The simplest way to add a button to an edit / view from is to use add_edit_button / add_view_button correspondinly. You can call this functions in the on_edit_form_created / on_view_form_created event handlers.

For example the Customers item uses this code in its client module to add buttons to a view form:

function on_view_form_created(item) {
    item.table_options.multiselect = false;
    if (!item.lookup_field) {
        var print_btn = item.add_view_button('Print', {image: 'icon-print'}),
            email_btn = item.add_view_button('Send email', {image: 'icon-pencil'}); { send_email() }); { print(item) });
        item.table_options.multiselect = true;

In this code the item’s lookup_field attribute is checkув and if it is defined (the view form is not created to select a value for a lookup field) the two buttons are created and for them JQuery click events are assigned to send_email and print functions declared in that module.