Monthly Archive for May, 2008

Form validation

Ngày trước tôi chỉ cần check cái input form (hữu hạn) để nó khác rỗng.

Ngày nay tôi phải:

  1. Check cả kiểu dữ liệu
  2. Check cả format (số điện thoại, số thẻ tín dụng…)
  3. Check các field mà không biết nó có thể tạo ra được bao nhiêu.
  4. Check các field & các field này ràng buộc với nhau. Từ trên xuống, có. Từ trái qua phải, có. Check chéo cũng có…
  5. … và nhiều cái phải check nữa sau này, qua quá trình làm việc sẽ dần dần đúc kết được thôi mà :)

Basic concept của 1 web developer khi validate form đó là…phải luôn focus dữ liệu. Thông báo được lỗi là tốt, nhưng chỉ ra lỗi vì đâu, lỗi ở chỗ nào, càng cụ thể thì càng tốt…cho người dùng (chứ dev thì mệt bỏ cha :D)

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

How to select the first option in a combo box?

Simply in jQuery (a Javascript framework - Write less, do more):

[-]?View Code JAVASCRIPT
1
$("#div_id option:first).attr("selected","selected"); 

Example: 

[-]?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
$('#myCombo').load(
                              'my_combo.php?foo=bar',
                               function() {
                                     $('#myCombo option:first).attr("selected","selected");
                               }
                      );
html:
<select id="myCombo"></select>
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Installed Simple Captcha system

Installed Simple Captcha system to hinder spammer :|

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

DirectoryIndex vs RewriteEngine

Tôi dùng modRewrite cho site hanhnguyenhotel.com. Mọi chuyện đều ổn nếu như thằng Kid không yêu cầu có cái trang intro (index.html). Mặc dù tôi đã để default file là index.html nhưng vẫn không ăn thua:

1
2
3
4
5
Options -Indexes
DirectoryIndex index.html index.php
RewriteEngine on
RewriteCond $1 !^(index\.html|modules|robots\.txt)
RewriteRule ^(.*)$ index.php?mod=$1 [L,QSA]

Chính xác thì phải thế này:

1
2
3
4
5
6
7
8
9
Options -Indexes
 
DirectoryIndex index.html index.php
 
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.html|modules|robots\.txt)
RewriteRule ^(.*)$ index.php?mod=$1 [L,QSA]

Okie, work fine!!!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]