zeroonea
06-07-2007, 22:25
{@:
Test: http://www.tinthoisu.net/htmlform/index.php
( Có 2 lựa chọn, sửa dụng client side valid (CSV) script và ko sửa dụng)
- Đây là 1 prj nhỏ để làm 1 tool cho PHP coder, nó giúp coder làm các form nhanh chóng với các tính năng hỗ trợ sau:
Features:
- Built-in server side (PHP) and client side (Javascript) field validation (SSV & CSV) for:
+ Field with specific format as Email, URL, number, even number, date or your customize with regular expression (regex)
+ Field equal to another (Ex: for password confirmation, etc..).
+ Field different from another (Ex: for reminder some fields like name that must not be equal to the actual password).
+ Range, max, min limitation for number field (interger and floating)
+ DB valid, now with two options InvalidOnExisted and ValidOnExisted (Useful for check exsiting username, email, etc..), also support ajax hot validation for DB valid
- Và còn khá nhiều thuộc tính phụ khác, sau khi form được kiểm tra thành công, bạn có thể xuất ra 2 loại câu query là insert và update
+ Với field bạn mún chỉ cho insert ko cho phép update (như ngày đăng ký): no_change_on_update
+ Ngược lại field chỉ cho phép update (như ngày hiệu chỉnh gì đó): no_insert
+ Chỉ update những field có nhập dữ liệu: no_update_when_empty
- Có thể xuất câu query riêng cho những field liên kết với nút submit trên form.
ví dụ: 1 form dài có 2 nút submit 1 là nút mặc định (name: submit) cho tất cả các field, 2 là nút submit để change riêng password (name: sm_password) có tác dụng trên vài field để nhập pass, tùy bạn ấn nút nào thì form sẽ valid và xuất câu query theo những field đó.
- class sẽ xuất ra dữ liệu "dạng thô", có thể tương thích với bất kỳ template engine nào hay json cho những prj ajax
- Còn còn các tính năng phụ khác hỗ trợ. Các bạn thấy còn thiếu cái gì và cần cái gì cho 1 form thì có thể góp ý cho mình hay, thanks
__________________________________
form để test bên trên được tạo từ 1 mảng rất đơn giản sau:
$eleData = array(
'fname' => array(
'field' => 'fname',
'title' => 'First Name: ',
'type' => 'text',
'control' => 'text',
'empty_msg' => 'Please enter your First Name',
'not_equal_to' => 'password',
'not_equal_to_msg' => 'First Name can\'t not similar to password',
),
'lname' => array(
'field' => 'lname',
'title' => 'Last Name: ',
'type' => 'text',
'control' => 'text',
'empty_msg' => 'Please enter your Last Name',
'not_equal_to' => 'password',
'not_equal_to_msg' => 'Last Name can\'t not similar to password',
),
'gender' => array(
'field' => 'gender',
'title' => 'Gender: ',
'type' => 'even_number',
'control' => 'radio',
'empty' => true,
'default_value' => 1,
'value_member' => array(1 => 'Male', 0 => 'Female'),
'item_list' => array(
array(
'title' => 'Male',
'static_value' => 1
),
array(
'title' => 'Female',
'static_value' => 0
),
)
),
'birthday' => array(
'field' => 'birthday',
'title' => 'Brithday: ',
'type' => 'shortdate',
'control' => 'calendar',
'calendar_lang' => 'vn',
'empty_msg' => 'Please enter your birthday',
'csv_event' => 'onChange:birthday|onBlur:birthday_calendar'
),
'country' => array(
'field' => 'country',
'title' => 'Country: ',
'type' => 'text',
'regex' => '^[a-z]{2}$',
'control' => 'combobox',
'control_body' => '<option value="vn">Việt Nam</option><option value="en">England</option>',
'item_list' => array(
array(
'title' => 'Campuchia',
'static_value' => 'kh',
),
array(
'title' => 'Lào',
'static_value' => 'lo',
)
)
),
'city' => array(
'field' => 'city',
'title' => 'City: ',
'type' => 'text',
'control' => 'text',
'empty' => true
),
'address' => array(
'field' => 'address',
'title' => 'Address: ',
'type' => 'text',
'control' => 'text',
'empty' => true
),
'username' => array(
'field' => 'username',
'title' => 'Username: ',
'type' => 'text',
'regex_msg' => 'Must be alphabet character, numeric and (6 - 32) character',
'regex' => '^[a-zA-Z0-9]{6,32}$',
'control' => 'text',
'empty_msg' => 'Please enter username you choose',
'csv_event' => 'onChange:username',
'db_valid' => array(
'type' => 'InvalidOnExisted',
'table' => 'customer',
'ajaxv' => true,
'ajaxv_url' => 'ajax.php',
),
'db_valid_msg' => 'This username is unavailable',
),
'password' => array(
'field' => 'password',
'title' => 'Password: ',
'type' => 'text',
'regex_msg' => 'Must be alphabet character, numeric and (6 - 32) character',
'regex' => '^[a-zA-Z0-9]{6,32}$',
'control' => 'password',
'empty_msg' => 'Please enter password',
),
're_password' => array(
'title' => 'Re-Type Password: ',
'type' => 'text',
'control' => 'password',
'empty_msg' => 'Please re-enter password',
'equal_to' => 'password',
'equal_to_msg' => 'Dose not match password above',
),
'email' => array(
'field' => 'email',
'title' => 'Email: ',
'control' => 'text',
'type' => 'email',
'note' => '(Format: name@domain.com)',
'db_valid' => array(
'type' => 'InvalidOnExisted',
'table' => 'customer',
'ajaxv' => true,
'ajaxv_url' => 'ajax.php',
),
'db_valid_msg' => 'This email is unavailable',
),
'homepage' => array(
'field' => 'homepage',
'title' => 'Homepage: ',
'type' => 'url',
'control' => 'text',
),
'date' => array(
'field' => 'register_date',
'value' => time(),
'server_side' => true,
'no_change_on_update' => true,
),
'taste' => array(
'field' => 'taste',
'type' => 'even_number',
'title' => 'Search engine you like: ',
'control' => 'checkbox',
'empty_msg' => 'Please choose at least 1 engine',
'select' => 1,
'item_list' => array(
array(
'title' => 'Google',
'static_value' => 1,
),
array(
'title' => 'Yahoo',
'static_value' => 2,
),
array(
'title' => 'Msn',
'static_value' => 3
),
array(
'title' => 'Ask',
'static_value' => 4,
),
array(
'title' => 'Zeroonea',
'static_value' => 5
),
),
),
'customer_sign' => array(
'field' => 'customer_sign',
'type' => 'text',
'title' => 'Sign:',
'note' => '(Customize your sign)',
'empty' => true,
'control' => 'editor',
'editor_type' => 'openwysiwyg',
'width' => '450',
'height' => '80',
),
);
:@}
Test: http://www.tinthoisu.net/htmlform/index.php
( Có 2 lựa chọn, sửa dụng client side valid (CSV) script và ko sửa dụng)
- Đây là 1 prj nhỏ để làm 1 tool cho PHP coder, nó giúp coder làm các form nhanh chóng với các tính năng hỗ trợ sau:
Features:
- Built-in server side (PHP) and client side (Javascript) field validation (SSV & CSV) for:
+ Field with specific format as Email, URL, number, even number, date or your customize with regular expression (regex)
+ Field equal to another (Ex: for password confirmation, etc..).
+ Field different from another (Ex: for reminder some fields like name that must not be equal to the actual password).
+ Range, max, min limitation for number field (interger and floating)
+ DB valid, now with two options InvalidOnExisted and ValidOnExisted (Useful for check exsiting username, email, etc..), also support ajax hot validation for DB valid
- Và còn khá nhiều thuộc tính phụ khác, sau khi form được kiểm tra thành công, bạn có thể xuất ra 2 loại câu query là insert và update
+ Với field bạn mún chỉ cho insert ko cho phép update (như ngày đăng ký): no_change_on_update
+ Ngược lại field chỉ cho phép update (như ngày hiệu chỉnh gì đó): no_insert
+ Chỉ update những field có nhập dữ liệu: no_update_when_empty
- Có thể xuất câu query riêng cho những field liên kết với nút submit trên form.
ví dụ: 1 form dài có 2 nút submit 1 là nút mặc định (name: submit) cho tất cả các field, 2 là nút submit để change riêng password (name: sm_password) có tác dụng trên vài field để nhập pass, tùy bạn ấn nút nào thì form sẽ valid và xuất câu query theo những field đó.
- class sẽ xuất ra dữ liệu "dạng thô", có thể tương thích với bất kỳ template engine nào hay json cho những prj ajax
- Còn còn các tính năng phụ khác hỗ trợ. Các bạn thấy còn thiếu cái gì và cần cái gì cho 1 form thì có thể góp ý cho mình hay, thanks
__________________________________
form để test bên trên được tạo từ 1 mảng rất đơn giản sau:
$eleData = array(
'fname' => array(
'field' => 'fname',
'title' => 'First Name: ',
'type' => 'text',
'control' => 'text',
'empty_msg' => 'Please enter your First Name',
'not_equal_to' => 'password',
'not_equal_to_msg' => 'First Name can\'t not similar to password',
),
'lname' => array(
'field' => 'lname',
'title' => 'Last Name: ',
'type' => 'text',
'control' => 'text',
'empty_msg' => 'Please enter your Last Name',
'not_equal_to' => 'password',
'not_equal_to_msg' => 'Last Name can\'t not similar to password',
),
'gender' => array(
'field' => 'gender',
'title' => 'Gender: ',
'type' => 'even_number',
'control' => 'radio',
'empty' => true,
'default_value' => 1,
'value_member' => array(1 => 'Male', 0 => 'Female'),
'item_list' => array(
array(
'title' => 'Male',
'static_value' => 1
),
array(
'title' => 'Female',
'static_value' => 0
),
)
),
'birthday' => array(
'field' => 'birthday',
'title' => 'Brithday: ',
'type' => 'shortdate',
'control' => 'calendar',
'calendar_lang' => 'vn',
'empty_msg' => 'Please enter your birthday',
'csv_event' => 'onChange:birthday|onBlur:birthday_calendar'
),
'country' => array(
'field' => 'country',
'title' => 'Country: ',
'type' => 'text',
'regex' => '^[a-z]{2}$',
'control' => 'combobox',
'control_body' => '<option value="vn">Việt Nam</option><option value="en">England</option>',
'item_list' => array(
array(
'title' => 'Campuchia',
'static_value' => 'kh',
),
array(
'title' => 'Lào',
'static_value' => 'lo',
)
)
),
'city' => array(
'field' => 'city',
'title' => 'City: ',
'type' => 'text',
'control' => 'text',
'empty' => true
),
'address' => array(
'field' => 'address',
'title' => 'Address: ',
'type' => 'text',
'control' => 'text',
'empty' => true
),
'username' => array(
'field' => 'username',
'title' => 'Username: ',
'type' => 'text',
'regex_msg' => 'Must be alphabet character, numeric and (6 - 32) character',
'regex' => '^[a-zA-Z0-9]{6,32}$',
'control' => 'text',
'empty_msg' => 'Please enter username you choose',
'csv_event' => 'onChange:username',
'db_valid' => array(
'type' => 'InvalidOnExisted',
'table' => 'customer',
'ajaxv' => true,
'ajaxv_url' => 'ajax.php',
),
'db_valid_msg' => 'This username is unavailable',
),
'password' => array(
'field' => 'password',
'title' => 'Password: ',
'type' => 'text',
'regex_msg' => 'Must be alphabet character, numeric and (6 - 32) character',
'regex' => '^[a-zA-Z0-9]{6,32}$',
'control' => 'password',
'empty_msg' => 'Please enter password',
),
're_password' => array(
'title' => 'Re-Type Password: ',
'type' => 'text',
'control' => 'password',
'empty_msg' => 'Please re-enter password',
'equal_to' => 'password',
'equal_to_msg' => 'Dose not match password above',
),
'email' => array(
'field' => 'email',
'title' => 'Email: ',
'control' => 'text',
'type' => 'email',
'note' => '(Format: name@domain.com)',
'db_valid' => array(
'type' => 'InvalidOnExisted',
'table' => 'customer',
'ajaxv' => true,
'ajaxv_url' => 'ajax.php',
),
'db_valid_msg' => 'This email is unavailable',
),
'homepage' => array(
'field' => 'homepage',
'title' => 'Homepage: ',
'type' => 'url',
'control' => 'text',
),
'date' => array(
'field' => 'register_date',
'value' => time(),
'server_side' => true,
'no_change_on_update' => true,
),
'taste' => array(
'field' => 'taste',
'type' => 'even_number',
'title' => 'Search engine you like: ',
'control' => 'checkbox',
'empty_msg' => 'Please choose at least 1 engine',
'select' => 1,
'item_list' => array(
array(
'title' => 'Google',
'static_value' => 1,
),
array(
'title' => 'Yahoo',
'static_value' => 2,
),
array(
'title' => 'Msn',
'static_value' => 3
),
array(
'title' => 'Ask',
'static_value' => 4,
),
array(
'title' => 'Zeroonea',
'static_value' => 5
),
),
),
'customer_sign' => array(
'field' => 'customer_sign',
'type' => 'text',
'title' => 'Sign:',
'note' => '(Customize your sign)',
'empty' => true,
'control' => 'editor',
'editor_type' => 'openwysiwyg',
'width' => '450',
'height' => '80',
),
);
:@}