Settings types
AbanteCart extension support following settings types:
- hidden
- input
- password
- textarea
- selectbox
- multiselect
- checkbox
- checkbox group
- file
- radio
Settings Values Validation (Starting v1.1.4)
In some cases there is a need to validate settings values provided by user. It is a developers responsibility to maintain stability of extension and AbanteCart core as a result of extension functionality. For this reason important to validate settings not only for required fields, but also for actual values and allowed value types. Validation is possible with 2 methods.
1. Pattern (regular expressions) based validation 2. Code side validation in custom function
Pattern based validation
This is a quick way to set validation to given setting field. Regular expression can be set per each setting filed to allow only specified value in the field.
<item id="email"> <type>input</type> <default_value></default_value> <pattern_validate>/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/</pattern_validate> </item>
Error text needs to be added to language XML with key like this: [extention_id]_[item_id]_validation_error or [extention_id]_email_validation_error in example above.
Code side validation
In case more advanced settings values validation required, you need to provide your own code to validate input and generate errors. This is done in a special validate.php file included on the main extension directory level. This file will be automatically included Function inside the file have to be named settingsValidation () { โฆ
function settingsValidation ( $settings_data = array()) { $error_items = array(); // array with failed validation data keys foreach($settings_data as $item_id=>$item_value){ if( !isset($item_value)){ $error_items[$item_id] = $language->get('errot_text_key') ; } } if ($error_items) { return array( 'result' => false, 'errors' => $error_items); } return array('result'=>true); }
Input: settingsValidation function will get an array with settings and values submitted by user.
array ( 'store_id' => '0', 'google_checkout_advanced_status' => '1', 'google_checkout_advanced_merchant_id' => '11111111111111111111', 'google_checkout_advanced_merchant_key' => 'dfjsdljadsfkjsdfklsdjfksdl', 'google_checkout_advanced_currency' => 'USD', 'google_checkout_advanced_total' => '0', 'google_checkout_advanced_test' => '1', 'google_checkout_advanced_merchant_calculation' => '1', 'google_checkout_advanced_order_status_id' => '1', 'google_checkout_advanced_location_id' => '0', 'google_checkout_advanced_sort_order' => '0', )
settingsValidation function will be call in all settings save and individual (quick) save. Keep in mind that validation needs to be done on each field separately. Required values handled by core and required="true" setting in the config
Return: return needs to be array with result = true/false and error message for each field with failed validation.
array( 'result'=>true );
array( 'result'=>false , 'errors' => array( 'field_name' => 'Missing Name' )