PDA

View Full Version : php class: htmlform, make form faster


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',
),
);


:@}

DHNguyen
07-07-2007, 00:04
http://upload32.worldispnetwork.com/upload32/I07/1183745136.jpg

zeroonea
07-07-2007, 00:24
{@:

- Ko hiểu bạn mún nói gì nữa ????, kiệm lời quá đi thôi

:@}

Miracle
07-07-2007, 12:53
Hay hay, mình mới biết tới cái này !

zeroonea
05-08-2007, 11:18
{@:

- Download HtmlForm: http://www.box.net/shared/nlki8or2ie
- Các bạn edit lại file Config.php và các trường, bảng trong file index.php cho thích hợp để sử dụng tính năng db valid.

:@}

nhtuong
05-08-2007, 19:12
Một module khá hoàn chỉnh! Chúc mừng em!
Anh thấy em có ghi chú tên mình trên header (By: zeroonea, Y!M: zeroonea, Email: zeroonea@gmail.com) nghĩa là do em phát triển hay em sưu tầm... Trên PHPClass anh thấy có một số tool về HTML Form và CSV có cách code khá giống em. Vậy em xử lý vấn đề bản quyền như thế nào? Cái này anh hỏi thật vì bạn anh hay gặp vấn đề này khi đưa các code lên đấu giá online. Và mình đành chịu thua vì lý do đơn giản là chưa đăng ký trên các diễn đàn lớn!
Anh rất vui vì có người cũng đang mày mò làm thư viện dùng chung này!

zeroonea
05-08-2007, 20:12
{@:

- Hì hì, ý tưởng nảy sinh khi em xem qua asp.net, nó làm form, valid form rất ư dễ dàng nhanh chóng, sau khi quyết định code, em search thử trên net có cái gì giống như thế chưa? em thấy có mấy class thực hiện công việc tương tự bên phpclasses.org, em xem qua list features của nó để phát triển theo, và thêm các tính năng của riêng em.

- Em chưa bao giờ xài các gói php của người ta viết, vì như thế là phải học thêm cách xài của nó, rất mất thời gian, lại có nhiều cái tương tự, có cái hay cái dỡ, chẳng nhẽ học hết, và đôi khi nó ko phù hợp với công việc của mình. Chỉ khi nào thực sự cần biết trong 1 dự án chung nhóm thì có lẽ em sẽ để mắt tới.

- Về việc đánh giá thì sau khi hoàn thiện, em sẽ đưa lên phpclasses.org cho mọi người đánh giá. Còn về phần em xác minh là 100% main module (2 class chính và 1 csv form.valid.js) là tự xử.

:@}