# Create / Edit

# fields ( field(s), reverse, tab_name, mode )

The table fields that you want to see when you edit or create entries. Takes a string, separated by commas, or an array of values. The second optional parameter causes the function to do the opposite, ie hides the selected fields. Takes tru / false, default false.

// hide fields
$xcrud->fields('name,email,city', true);

You can create tabs for some fields, just set tab name in 3rd parameter:

$xcrud->fields('username,email', false, 'Account info');
$xcrud->fields('country,city,sex,age', false, 'Personal');

Also you can use different columns for different actions (create, edit, view), set action in 4th parameter:

$xcrud->fields('first_name,last_name,country', false, false, 'view');

You can play with combination of this parameters. Tabs is unaviable if second parameter is true.

# show_primary_ai_field ()

Takes true / false, setting the display of primary auto-increment field when editing the entry.



Primary auto-increment field will always be disabled.

# readonly ( field(s), mode )

Sets the selected fields attribute 'readonly'. Takes a string, separated by commas, or an array of values. Second paremeter sets mode (create, edit), default is all.


# disabled ( field(s), mode )

Sets the selected fields attribute 'disabled'. Takes a string, separated by commas, or an array of values. Second paremeter sets mode (create, edit), default is all.


// separate screens

# readonly_on_create (), readonly_on_edit (), disabled_on_create (), disabled_on_edit ()

Do the same thing as the methods above, but allow you to separate the creation and editing. This methods are deprecated and will be deleted.

# no_editor ( field(s) )

Allows you to load a text box without an editor (it has an effect when editor is loaded). Takes a string, separated by commas, or an array of values.


# change_type ( field(s), type, default, params_or_attr )

Allows you to change the visual representation of the field. Takes the name of the field, a new type, default value, and an additional parameter (a set of values ​​for lists or the length of the field for the text boxes). Available field types: bool, int, float, text, textarea, texteditor, date, datetime, timestamp, time, year, select, multiselect, password, hidden, file, image, point.



See more about change_type() in Field types section.


Hidden type will add hidden input in form. Use fields() and pass_var() methods to hide fields and put custom data in your table, if you need to preserve your data (pass_var() will not add any input).

# pass_var ( field, value, mode )

Allows you to record a variable or data directly in the database, bypassing the add / edit form. The field may not be present in the field, edit field will not affect your data. Function takes the name of the field in the first parameter, and your data, or variable in the second. Optional third parameter is available that allows you to clearly define where you want to paste the data - when creating or editing.

$xcrud->pass_var('user_id', $user_id);
$xcrud->pass_var('created', date('Y-m-d H:i:s'), 'create');
$xcrud->pass_var('was_edited', 'Yes, it was!', 'edit');
//using field from current row
$xcrud->pass_var('modified', '{last_action}');

# pass_default( field, value )

Pass default value into field, takes the name of the field and default value, or array in first parameter.

$xcrud->pass_default(array('name' => 'Joe', 'city' => 'Boston'));

# condition ( field, operator, value, method, parameter(s) )

Allows you to make some changes based on the data in the form.


field - table field operator - operator value - value method - method executed when triggered conditions parameters - parameters passed to the method.

Supported methods

readonly(), readonly_on_create(), readonly_on_edit(), disabled(), disabled_on_create(), disabled_on_edit(), no_editor(), validation_required(), validation_pattern().

Supported operators

=, >, <, >=, <=, !=, ^=, $=, ~=.

// if access < 5 than make password, email and username not editable
// or
  • ^= - starts with
  • $= - ends with
  • ~= - contains.

# validation_required ( field(s), chars )

A simple rule that takes the name of the field and the number of characters (default - 1) or an array.

$xcrud->validation_required(array('name' => 1, 'city' => 3));

# validation_pattern ( field(s), pattren )

Uses a simple validation pattern to selected fields. Takes the field name and the name of the pattern or array. Available patterns: email, alpha, alpha_numeric, alpha_dash, numeric, integer, decimal, natural. Also you can use your own regular expression in second parameter.

$xcrud->validation_pattern('name', 'alpha');
$xcrud->validation_pattern('email', 'email');
$xcrud->validation_pattern(array('name' => 'alpha', 'email' => 'email'));
// or
$xcrud->validation_pattern('username', '[a-zA-Z]{3,14}');

Sends emails when data was changed: on create, update or both. Takes email from entry (you must define column in first parameter) and carbon copy list (if defined) from second parameter(can be comma-separated string or array). You must define subject in 3rd and email body in 4th parameter. You can define additional link for email in 5th parameter (optional).

In message body you can use simple tags to retrive some values from row, just write column name in {}.

$xcrud->alert('email','admin@example.com','Password changed','Your new password is {password}');
$xcrud->alert_create('email','','Email Testing','Hello!!!!!');

# mass_alert(), mass_alert_edit(), mass_alert_create()

The same like alert(), but it send message to all emails from selected table.


$xcrud->mass_alert('user','email','subscribe = 1','Email test','Hello!');

# page_call(url, data_array, param, param_value, method), page_call_create(...), page_call_edit(...)

Sends http query to another file/page. This method not receive any data. It only sends request when row was added or changed.

You can define any data into data_array, including {field_tags}, this data will be received in target page like $_GET or $_POST array. If param is defined, method will run only if field value from current row (param) will be equal to param_value. Method defines type of request (get or post), default is get.

$xcrud->page_call('http://mysite/admin/mytarget.php', array('id'=>'{user_id}','text'=>'User {user_name} here!'));


If your site using authorization, you can try to send browser cookie with request. This featue is experimental and can be turn on from configuration file. BE CAREFUL: DON'T USE IT FOR REQUESTS TO EXTERNAL SITES!!!

# set_attr( field(s), array attr )

Allows to set custom attributes for fields in edit form. field(s)

Form field(s), attr - assoc array with attributes.

Last Updated: 3/11/2021, 5:43:48 PM