[Maple-user: 225] エラー画面を経由しないで入力画面を再表示

Back to archive index

h-tag****@secom***** h-tag****@secom*****
2006年 3月 13日 (月) 16:54:24 JST


田口と申します。

入力画面・確認画面・完了画面からなるデータ入力のアプリを作成したいのですが、
「example3」が一番近いと思い、これを修正してみようと考えました。
ただexample3では、入力データにエラーがあった場合、一度エラー画面を表示させてから
入力画面を表示しています。ここがまだるいので、エラー画面なしで入力画面を
表示したいのです。

入力画面で部署の選択をさせたいと思い、(部署一覧は本当はファイルにあるのですが)
簡略化して、Form.class.phpで直接設定するようにし、form.htmlでは、confirmでの
データチェックでエラーのとき、再びform.htmlがエラーメッセージと共に表示される
ようにしました。

しかし、こうすると部署の選択が、
<select name="dept">
<option label="" value="0"></option>
</select>
になって表示されません。Form.class.phpが実行されないからだろうと思いますが、
そうすると、このような場合、どう書けばよいのでしょうか?
部署一覧は、確認画面でも、コードではなく日本語名称で表示したいので、confirmでも
必要です。完了画面では不要です。
Smartyを使ってます、またファイルは全てEUCにしています。


/webapp/modules/examples/smarty/example3/form/Form.class.php ここから
<?php
class Examples_Smarty_Example3_Form
{
    var $name;
    var $email;
    var $dept;     // 追加
    var $deptList; // 追加

    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Examples_Smarty_Example3_Formが実行されました", "Examples_Smarty_Example3_Form#execute");

        $this->deptList["0"] = "▼選択してください。"; // 追加
        $this->deptList["1001"] = "管理部";            // 追加
        $this->deptList["1002"] = "総務部";            // 追加
        $this->deptList["1003"] = "開発部";            // 追加

        return "success";
    }
    
    // 追加
    function getDeptList()
    {
      return $this->deptList;
    }
}
?>
/webapp/modules/examples/smarty/example3/form/Form.class.php ここまで

/webapp/modules/examples/smarty/example3/form/maple.ini ここから(変更なし)
[View]
success = "examples/smarty/example3/form.html"
/webapp/modules/examples/smarty/example3/form/maple.ini ここまで

/webapp/modules/examples/smarty/example3/confirm/Confirm.class.php ここから
<?php
class Examples_Smarty_Example3_Confirm
{
    var $name;
    var $email;
    var $dept;
    var $deptList;
    function execute()
    {
        $log =& LogFactory::getLog();
        $log->debug("Examples_Smarty_Example3_Confirmが実行されました", "Examples_Smarty_Example3_Confirm#execute");

        $this->deptList["0"] = "(選択なし)";
        $this->deptList["1001"] = "管理部";
        $this->deptList["1002"] = "総務部";
        $this->deptList["1003"] = "開発部";

        return "success";
    }
    
    function getDeptName()
    {
      return $this->deptList[$this->dept];
    }
}
?>
/webapp/modules/examples/smarty/example3/confirm/Confirm.class.php ここまで

/webapp/modules/examples/smarty/example3/confirm/maple.ini ここから
[Session]
mode = start

[Token]
mode = build

[Convert]
name,email.trim =
email.toHalf =

[Validate]
name.required = "1,名前を入力してください"
name.maxlength = "0,名前は全角20文字以内で入力してください,40"
email.required = "1,メールアドレスを入力してください"
email.maxlength = "1,メールアドレスは60文字以内入力してください,60"
email.mail = "0,メールアドレスを正しく入力してください"

[View]
success = "examples/smarty/example3/confirm.html"
input   = "examples/smarty/example3/form.html"     <===ここだけ変更(error => form)
/webapp/modules/examples/smarty/example3/confirm/maple.ini ここまで

/webapp/templates/examples/smarty/example3/form.html ここから
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=EUC-JP">
<title>example3</title>
</head>
<body>

以下の項目を入力してください。<br>
<br>

{errorList->getMessages assign=messages}
{if $messages}
  {foreach from=$messages|smarty:nodefaults item=message}
    {$message}<br>
  {/foreach}
  <br>
{/if}

<form method="post" action="{$scriptName}">
<input type="hidden" name="action" value="examples_smarty_example3_confirm">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td>名前</td>
<td><input type="text" name="name" value="{$action.name}" size="20"></td>
</tr>
<tr>
<td>メールアドレス</td>
<td><input type="text" name="email" value="{$action.email}" size="40"></td>
</tr>

<tr>
<td>部署</td>
<td>

{action->getDeptList assign=deptList}
{html_options name="dept" options=$deptList selected=$action.dept}
</td>
</tr>

<tr>
<td colspan="2"><input type="submit" value="登録"></td>
</tr>
</table>
</form>

</body>
</html>
/webapp/templates/examples/smarty/example3/form.html ここまで

/webapp/templates/examples/smarty/example3/confirm.html ここから
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=EUC-JP">
<title>example3</title>
</head>
<body>

以下の入力でよろしいですか?<br>
<br>

<form method="post" action="{$scriptName}">
<input type="hidden" name="{$token.name}" value="{$token.value}">
<input type="hidden" name="name" value="{$action.name}">
<input type="hidden" name="email" value="{$action.email}">
<input type="hidden" name="dept" value="{$action.dept}">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td>名前</td>
<td>{$action.name}</td>
</tr>
<tr>
<td>メールアドレス</td>
<td>{$action.email}</td>
</tr>

{action->getDeptName assign=deptName}
<tr>
<td>部署</td>
<td>{$deptName}</td>
</tr>

<tr>
<td colspan="2">
<input type="submit" name="dispatch_examples_smarty_example3_form" value="再入力">
<input type="submit" name="dispatch_examples_smarty_example3_done" value="登録">
</td>
</tr>
</table>
</form>

</body>
</html>
/webapp/templates/examples/smarty/example3/confirm.html ここまで

Regards,
h-taguchi @ secom




Maple-user メーリングリストの案内
Back to archive index