PEAK XOOPS - picoのsmarty pluginによる機能拡張(1) in englishin japanese

Archive | RSS |
XOOPS
XOOPS : picoのsmarty pluginによる機能拡張(1)
Poster : GIJOE on 2007-09-23 15:41:58 (16089 reads)

in englishin japanese
"HTMLでValidateするフォームメール" という記事を何回か連続で書いてきましたが、この意味がなかなか判りづらいかもしれません。「POSTデータ処理を行うための基準を、HTMLフォームそのものに求める」と書いても、判らない人には判らないでしょう。

というわけで、もう少し判りやすい実例で行きましょう。

その1
「商品説明コンテンツに、共通の問い合わせフォームを埋め込む」

picoを使ってカテゴリーごとに商品ページを作ったとしましょう。それらの一つ一つに、問い合わせフォームを埋め込んでいくなんて、それこそナンセンスです。

こんな用途では、formmailプラグインとpicoプラグインの組み合わせでバッチリです。
商品説明ページはこんな感じで作ります。(SmartyフィルターをONにすること)


(商品説明部分)

<{capture}>
<{pico id="(フォームを記述したコンテンツ番号)"}>
<{/capture}>
<{formmail4fleamarket mail_body_pre="以下の商品について問い合わせがありました。\nいずれかの連絡先までご連絡ください。\n\n" from_name="商品問い合わせ担当" cc_field_name="youremail" cc_mail_subject="確認メール" cc_mail_body_pre="お問い合わせありがとうございました。\n以下が確認内容です。\n"}>


まず <{pico id=""}> の部分がミソです。

<form>
  お名前: <input type="text" name="お名前" class="required" /><br />
  email: <input type="text" name="youremail" class="email" />
  <input type="submit" />
</form>

とりあえず、こんな内容のフォームを、picoコンテンツとして作っておいて、そのコンテンツ番号を、id="" の中に書き込むのです。そうすることで、全ての商品について、共通のフォームを利用できることになります。この商品には別のフォーム、なんてことも、それぞれ対応するコンテンツ番号にすれば良いだけです。

もちろん、別のpicoにあるフォームでも構いません。その場合は、
<{pico id="(コンテンツ番号)" dirname="(dirname)"}>
とdirnameで指定します。

次に、<{formmail}> の部分ですが、今度は、随分と長くなっています。
実はこれ全部、formmailプラグインの引数です。

この引数によって、フォームメールの各種動作を変更することが出来ます。
ここでは、このサンプルで使われている引数だけ解説しておきます。

mail_body_pre: XOOPSから管理者に送られるメール本文で、問い合わせ内容の前に置かれるテキストです
from_name: メールの送信者名です
cc_field_name: フォーム回答者にも確認メールを送る際に、その宛先となるメールアドレスとなるフィールド名を指定します(ここではyouremail)
cc_mail_subject: 確認メールのSubjectです
cc_mail_body_pre: 確認メール本文で、問い合わせ内容の前のテキストです

引数をいろいろいじって試してください。


Printer friendly page Send this story to a friend

Comments list

gigamaster  Posted on 2007/9/30 6:43 | Last modified
Hi Gijoe,

My fault. I was waiting to finish modules translation and start to play with Pico.
So, I did not read the "README" file and i put myself in troubles with my smarty bug

I promise. Next time i will try to calm and start with README - that is also why that file exist !

GIJOE  Posted on 2007/9/30 6:11 | Last modified
hi gigamaster.

Quote:

And as usual i start to put my self in troubles
changing "formmail4fleamarket" to "formvalidation"
I had to go through phpmyadmin to fix smarty bug..
If you copy the smarty plugin like "formmail" with different name, you have to change the code of the plugin.

function smarty_function_formmail( $params , &$smarty )
{
	$controller =& new PicoFormProcessBySmartyFormmail() ;
	$controller->parseParameters( $params ) ;

	// toEmails from 'adminmail'
	if( empty( $controller->toEmails ) ) {
		if( trim( $GLOBALS['xoopsConfig']['adminmail'] ) != '' ) {
			$controller->toEmails[] = $GLOBALS['xoopsConfig']['adminmail'] ;
		}
	}

	$controller->execute( $params , $smarty ) ;
}


class PicoFormProcessBySmartyFormmail extends PicoFormProcessBySmartyBase
{
	function __construct()
	{
		$this->mypluginname = 'formmail' ;
	}

	function executeLast()
	{
		$this->sendMail() ;
	}

}
gigamaster  Posted on 2007/9/29 7:41 | Last modified
After translation, i start to play with Pico,
as you all know now, my favorite module

And as usual i start to put my self in troubles
changing "formmail4fleamarket" to "formvalidation"
I had to go through phpmyadmin to fix smarty bug..

Finally I reset everything and start with a new form.
Please, check the following : example.
Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!