
SOY2HTMLでテキストフォームを設置する - HTMLInput編でプラグインの設定用の入力(テキスト)フォームの設置を見ました。
今回は更にテキストエリアを追加してみます。
テキストエリアを設置します。
構築は前の記事のダミープラグインのコードに加えていきます。
テキストエリアの設置はHTMLTextAreaクラスを利用して、
前回追加した入力フォームの下に下記のコードを追加します。
$this->createAdd("content", "HTMLTextArea", array(
"name" => "Config[content]",
"value" => "huga"
));
いつも通り、短縮形を見ておくと、
$this->addTextArea("content", array(
"name" => "Config[content]",
"value" => "huga"
));
これまた今回も前回同様、ダミープラグインには短縮形の方で記述します。
DummyPluginConfigPage.class.php
<?php
class DummyPluginConfigPage extends WebPage {
private $configObj;
function __construct(){}
function doPost(){
if(soy2_check_token()){
//入力内容の保存
SOYShop_DataSets::put("dummy_plugin.config", $_POST["Config"]);
$this->configObj->redirect("updated");
}
$this->configObj->redirect("failed");
}
function execute(){
parent::__construct();
$this->addForm("form", array(
"method" => "POST"
));
$this->addInput("title", array(
"name" => "Config[title]",
"value" => "hoge"
));
$this->addTextArea("content", array(
"name" => "Config[content]",
"value" => "huga"
));
}
function setConfigObj($configObj){
$this->configObj = $configObj;
}
}
続いて、対になるHTMLファイルの方に新たに作成したsoy:id付きテキストフォームを設置します。
DummyPluginConfigPage.html
<form soy:id="form"> <dl> <dt>タイトル</dt> <dd> <input type="text" soy:id="title"> </dd> <dt>本文</dt> <dd> <textarea soy:id="content"></textarea> </dd> </dl> <input type="submit" value="押す"> </form>
テキストフォームのタグを追加できたら、実際に画面を確認してみて、

テキストエリアが追加された事を確認します。
該当箇所のソースコードを確認してみると、
<textarea name="Config[content]">huga</textarea>
このようにnameと(JavaScriptでいうところの)innerTextの箇所に値が追加されていました。
この値は
$this->addTextArea("content", array(
"name" => "Config[content]",
"value" => "huga"
));
addTextAreaの第二引数の配列内で指定した値が反映されています。
textareaタグにはvalue属性がないが、前回のaddInputの際のinputタグのvalue属性のような振る舞いをします。
今回も以前同様、HTMLTextAreaの実際のコードを見ておきます。
/common/lib/soy2_build.phpを開きclass HTMLTextAreaでテキスト検索して、
/**
* @package SOY2.SOY2HTML
*/
class HTMLTextArea extends HTMLFormElement{
var $tag = "textarea";
const SOY_TYPE = SOY2HTML::HTML_BODY;
var $text;
function setText($value){
$this->text = $value;
}
function setValue($value){
$this->text = $value;
}
function getText(){
return (string) $this->text;
}
function getObject(){
return "\n".htmlspecialchars($this->getText(),ENT_QUOTES,SOY2HTML::ENCODING);
}
}





