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

$xcrud->fields('name,email,city');
//or
$xcrud->fields(array('name','email','city'));
// 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.

$xcrud->show_primary_ai_field(true);

INFO

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.

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

# 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( field(s), array attr )

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

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

$xcrud->set_attr('user',array('id'=>'user','data-role'=>'admin'));
Last Updated: 3/11/2021, 5:43:48 PM