PEAK XOOPS - Formmail validated by HTML (3) in englishin japanese

Archive | RSS |
XOOPS
XOOPS : Formmail validated by HTML (3)
Poster : GIJOE on 2007-09-06 06:31:17 (9763 reads)

in englishin japanese
Here is a document how to validate POST data via pure HTML.


(A) How to get POST's indexes should be received?

Just get "name" attributes in the HTML.
# Though it is difficult to treat array like hobbies[], I skip it now.


(B) How to get field's title?

This system gets field's title from <label> corresponding the <input> from HTML.


(C) How to judge whether the field is essential or not?

This system judges them by their filed's name.
If a field contains '_required' in its name, the field will be regarded as essential.
refer the sample HTML in (1).
The field of 'name_required' is essential.


You can specify validation rule by "class" of <input>. (pico >= 1.51)
refer the sample HTML in (1).
<input> for 'name' has the class of "required".
Then the field will be essential.


(D) How to do "TYPE-SAFE" or "TYPE-AUTO-CONVERSION"?

This "type" contains not only int,double,string etc, but also "telephone number","email address" etc.

This system judges them their filed's name like (C).
eg) if a field contains 'email' in its name, the field will be validated as "email address".


You can specify validation rule by "class" of <input>. (pico >= 1.51)
refer the sample HTML in (1).
<input> for 'email' has the class of "email".
Then the field of 'email' will be checked by the rule of RFC2822.

Of course, you can specify classes multiply.
If an <input> has class="email required", the field will be essential AND validated as "email address".


Related articles
Printer friendly page Send this story to a friend

Comments list

GIJOE  Posted on 2007/9/6 13:02
genetさん、こんにちは。
Quote:

genet wrotes:
(C), (D) で悩んでおられるのは、入力必須とかデータ型の変更がid (or name) 属性に影響してしまうのがまずいということですよね?
そうです。
他にも、「必須条件指定専用のhiddenな<input>を定義する」とか「<label>内に特定の文字列があったら必須にする」なんてのを検討しましたが、イマイチしっくりきませんでした。
が…

Quote:
既に検討済みかも知れませんが、class属性を使ってみてはどうでしょう?class属性は直接見栄えに影響しませんし、スペース区切りでいくつも値を設定できますから邪魔にならないと思います。
おおっ!
classを使うのは、まったく頭にありませんでした!

将来的に、HTMLパーサ部分をDOMでまともに処理するやり方に変更したとしても、class指定なら普通にアクセスできますね。

まさに文句なしです。

この案、パクらせていただきます。
genet  Posted on 2007/9/6 11:40
(C), (D) で悩んでおられるのは、入力必須とかデータ型の変更がid (or name) 属性に影響してしまうのがまずいということですよね?既に検討済みかも知れませんが、class属性を使ってみてはどうでしょう?class属性は直接見栄えに影響しませんし、スペース区切りでいくつも値を設定できますから邪魔にならないと思います。
Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!