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

Archive | RSS |
XOOPS
XOOPS : Formmail validated by HTML (1)
Poster : GIJOE on 2007-09-04 06:00:47 (15710 reads)

in englishin japanese
I implemented "Formmail validated by HTML" for pico 1.50

You may ask "What is new?"

OK.
This system uses Template data written by HTML designer as "Validator".
You need not XML definition etc.

And I don't value the module like liaise or class of XoopsForm, because such HTML generating system kills the liberty for HTML design.

I believe this system makes both designers and programmers happy.

Anyway try to make a contents like this.

Filters: Turn 'Smarty(XoopsTpl)' on.
All of the rest options should be turned off.
(Also "body cache")



<{capture}>
<form>

<label for="yourname">Your Name</label>
<input type="text" name="yourname" id="yourname" class="required" />
<br />

Fruit:
<label for="checkbox_orange">orange</label>
<input type="checkbox" name="favorite_fruit[]" id="checkbox_orange" class="required" value="orange" />
<label for="checkbox_apple">apple</label>
<input type="checkbox" name="favorite_fruit[]" id="checkbox_apple" class="required" value="apple" />
<label for="checkbox_pear">pear</label>
<input type="checkbox" name="favorite_fruit[]" id="checkbox_pear" class="required" value="pear" checked="checked" />
<br />

<label for="youremail">email</label>
<input type="text" name="youremail" id="youremail" class="email" />
<br />

<label for="selbox">Select Box</label>
<select name="selbox" id="selbox" class="required">
	<option value="">-- select it --</option>
	<option value="0">0</option>
	<option value="1">1</option>
	<option value="2" selected="selected">2</option>
	<option value="3">3</option>
</select>
<br />

<label for="content">Content</label>
<textarea name="content" id="body"></textarea>
<br />

<input type="submit" value="Confirm" />
</form>
<{/capture}>
<{formmail}>


Related articles
Printer friendly page Send this story to a friend

Comments list

jidaikobo  Posted on 2009/2/9 23:40
jidaikobo です。

しつこく FormProcessByHtml.class.php の件ですが、ひとつ気づいたことがあります。

134行目、
if( strstr( $fieldsetblock , $tag ) && preg_match( '#<legend[^>]*>([^<]+)</legend>#' , $fieldsetblock , $sub_regs ) ) {

ですが、legend の中で、html のタグが出てきたときに、legend の値を取得しないようになっているとおもいます。
でも、legend 自体は、DTD としては、中になにか要素がきてもいい要素(*)なので、たとえば span、strong とかがくると、値を取得できなくなります。
フォームの html 側でいくらでも回避方法はあるのですが、せっかく自由に html がかける仕組みですし、

if( strstr( $fieldsetblock , $tag ) && preg_match( '#<legend[^>]*>(.+)</legend>#' , $fieldsetblock , $sub_regs ) ) {

としちゃうとマズいでしょうか?
あいかわらず、なにか勘違いしてたらすみません……

* %inline だからインライン要素限定ですが。
GIJOE  Posted on 2008/12/9 4:44
ditamineさん、こんにちは。

Quote:

ここ、私は否定先読みを使って
if( preg_match( '#<fieldset(?:(?!fieldset).)*'.preg_quote($tag).'.*</fieldset>#isU' , $form_html , $regs ) ) {
とやってました。一応これで上手くいくかと思います。
ありがとうございます。
否定先読み苦手なんですよね
今回はこのまま行きますが、今後何かの折には役立たせていただきます。

Quote:
実は1.60くらいでバグかな?と思っていたのですが、なんやかんやで先送りになってました。その時点でご報告していればよかったですね・・・
ぜひお気軽にバグ報告ください
ditamine  Posted on 2008/12/8 10:50 | Last modified
こんにちは、こちらに投稿させて頂くのは初めてです。いつもpico使わせて頂いております。

すでに解決済みのところ恐縮なのですが、

Quote:

<fieldset>と<legend>の間に</fieldset>が見つかったら終了、って正規表現がパッと書けなかったので、preg_split()でいったん分割しました。

ここ、私は否定先読みを使って
if( preg_match( '#<fieldset(?:(?!fieldset).)*'.preg_quote($tag).'.*</fieldset>#isU' , $form_html , $regs ) ) {
とやってました。一応これで上手くいくかと思います。

実は1.60くらいでバグかな?と思っていたのですが、なんやかんやで先送りになってました。その時点でご報告していればよかったですね・・・
jidaikobo  Posted on 2008/12/5 15:57
jidaikobo です。

Quote:

GIJOE wrotes:
<fieldset>と<legend>の間に</fieldset>が見つかったら終了、って正規表現がパッと書けなかったので、preg_split()でいったん分割しました。

1.75aを試してみてください。
試してみました。バッチリです

Quote:
# いただいたコードが悪いってことはないのですが、<fieldset>のブロックという概念から外れてしまうので。
いや、おっしゃる通りだと思います。
そういう論理一貫性があると気持ちいいですね。

この form 解析の仕組みも、ソースコードを拝見して、とても考え方の参考になりました。

ご対応ありがとうございました〜。
GIJOE  Posted on 2008/12/5 3:41
Quote:

jidaikobo wrotes:
pico の survey プラグインで遊ぼう!の picoSurveyAssistant を書いていて気づいたんですが、pico の formmail プラグインで、checkbox や radio が複数あるフォームの場合、最初の要素の legend が、以降すべての checkbox と radio のタイトルとして、メールで送られているようでした。
本当ですね

<fieldset>と<legend>の間に</fieldset>が見つかったら終了、って正規表現がパッと書けなかったので、preg_split()でいったん分割しました。

1.75aを試してみてください。

# いただいたコードが悪いってことはないのですが、<fieldset>のブロックという概念から外れてしまうので。

## コメントのtypoも修正しました
jidaikobo  Posted on 2008/12/4 15:20 | Last modified
pico の survey プラグインで遊ぼう!の picoSurveyAssistant を書いていて気づいたんですが、pico の formmail プラグインで、checkbox や radio が複数あるフォームの場合、最初の要素の legend が、以降すべての checkbox と radio のタイトルとして、メールで送られているようでした。

で、/trust_path/modules/pico/class/FormProcessByHtml.class.php の 132 行目あたりをチェックしてみました。

// search the nearest <regend> for radio/checkbox
if( preg_match( '#<fieldset.*'.preg_quote($tag).'.*</fieldset>#isU' , $form_html , $regs ) ) {
	if( preg_match( '#<legend[^>]*>([^<]+)</legend>#' , $regs[0] , $sub_regs ) ) {
		$label = strip_tags( @$sub_regs[1] ) ;
	}
}

これを下記のようにしてみたところ、目的の legend の値が、タイトルになって送られたように思われます。
#あっ、コメントにも typo が…… ^^;

// search the nearest <legend> for radio/checkbox
if( preg_match( '#<fieldset.*'.preg_quote($tag).'.*</fieldset>#isU' , $form_html , $regs ) ) {
	if( preg_match_all( '#<legend[^>]*>([^<]+)</legend>#' , $regs[0] , $sub_regs ) ) {
		$sub_regs_tmp = isset( $sub_regs[1] ) ? array_pop( $sub_regs[1] ) : '' ;
		$label = strip_tags( $sub_regs_tmp ) ;
	}
}

これが最良の措置かどうかわからないのですが、ご報告まで〜。
gigamaster  Posted on 2007/9/5 7:20 | Last modified
Since the beginning of hodajuku, i start to work on modules from Chatnoir, Marijuana, Taquino, Wye and some others. I got some issues with translation and it is taking me more time than expected to work on a new U.I.

The web is changing, and there's a new definition/mission for cms/frameworks. The project is missing a script for creating and processing web forms and a distribution with the best D3 modules that match such requirements, communicates and powers human being creativity.
I'm sure the distribution will be a very good thing for everyone.

P.S. 私の名前は綴りである = 言うべき私達の表現...非常に熱狂的な人
but similar to kurekurekun 多分それは本当である !!!
GIJOE  Posted on 2007/9/5 6:16
hi gagamaster.

Quote:

I hope to read more about this new feature and
possibilities to replace liaise or formulize.

I know almost designers avoid to use liaise or formulize because of their inconviniences of design.

Only "InquirySP" made by marijuana can be selected by designers in Japan.
Though "InquirySP" is a good module, it contains a lot of hard-coded Japanese, sadly...
gigamaster  Posted on 2007/9/4 7:19
Wow !!!

This is another big step of my favorite module!


I hope to read more about this new feature and
possibilities to replace liaise or formulize.

Best Regards,

Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!