# Create / Edit

# fields()

Set the table fields that you want to display in the edit or create screens.

Parameter Type Default Description
$fields string '' Comma separated string or string array of field names.
$reverse boolean false If set to true, the $fields specified will be hidden. Defaults to false.
$tabname string false The tab name to group under $fields under.
Remaining table fields, if ungrouped under other tabs by more calls to the fields() method, will be grouped under the default tab, if set using default_tab().
Tabs are unavailable if $reverse is true.
$mode string false Specifies which xCRUD detail view to display the fields in.
Accepted values are: 'create', 'edit', 'view'.
$xcrud->fields('name,email,city');
//or
$xcrud->fields(array('name','email','city'));
// hide fields
$xcrud->fields('name,email,city', true);


// group some fields under tabs.
$xcrud->fields('username,email', false, 'Account info');
$xcrud->fields('country,city,sex,age', false, 'Personal');


// mode: show in view detail screen 
$xcrud->fields('first_name,last_name,country', false, false, 'view');

# default_tab()

Sets the default tab name under which all other ungrouped fields will appear. Fields are grouped using the fields() method.

Parameter Type Default Description
$name mixed false Default tab name.

# show_primary_ai_field()

Display the PRIMARY AUTO_INCREMENT field in create, view and edit screens. Input is disabled in create and edit views.

Parameter Type Default Description
$bool boolean true Display the PRIMARY AUTO_INCREMENT field if set to true and otherwise for false.
$xcrud->show_primary_ai_field();

# 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.

$xcrud->readonly('name,email,city');
//or
$xcrud->readonly(array('name','email','city'));

# 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.

$xcrud->disabled('name,email,city');
//or
$xcrud->disabled(array('name','email','city'));

// separate screens
$xcrud->disabled('email','edit');

# 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.

$xcrud->no_editor('name,email,city');
//or
$xcrud->no_editor(array('name','email','city'));

# 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.

$xcrud->change_type('last_visit','timestamp');
$xcrud->change_type('nickname','text','',20);
$xcrud->change_type('email','multiselect','email2@ex.com','email1@ex.com,email2@ex.com,email3@ex.com,email4@ex.com,email5@ex.com');

INFO

See more about change_type() in Field types section.

IMPORTANT

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('name','Joe');
//or
$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.

Parameters:

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

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

$xcrud->condition('access','<','5','disabled','password,email,username');
// if access < 5 than make password, email and username not editable
// or
$xcrud->condition('access','<','5','validation_pattern',array('username','[0-9A-Za-z]+'));
  • ^= - starts with
  • $= - ends with
  • ~= - contains.

# unique()

Set the table fields whose value is unique.

Parameter Type Default Description
$fields string '' Comma separated string of field names.

# 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('name');
$xcrud->validation_required('city',3);
//or
$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');
//or
$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.

mass_alert(email_table,email_column,email_where,subject,message,link,curent_param,param_value)

$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!'));

IMPORTANT

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()

Used to set custom HTML attributes for fields in the edit view.

Parameter Type Default Description
$fields mixed '' Comma separated string or string array of field names.
$attr array array() Associative array of HTML attributes. The array keys specify the HTML attribute and the array value becomes the HTML attribute value.
// Outputs something like 
// <input name="user" id="user",data-role="admin">
$xcrud->set_attr('user', array('id'=>'user','data-role'=>'admin'));
Last Updated: 11/1/2021, 10:10:17 PM