Permalink
Browse files

「存在する日付の判別」機能を追加したカスタマイズ例

  • Loading branch information...
1 parent ea33bde commit a9d8935f3f03506c89ed0a5bceaff4594f124e39 @dounokouno committed Oct 30, 2015
Showing with 97 additions and 1 deletion.
  1. +6 −0 config/config.yml
  2. +2 −1 index.php
  3. +16 −0 input.html
  4. +73 −0 lib/exTransmitMail.php
View
@@ -0,0 +1,6 @@
+config:
+ to_email: info@example.com
+ to_subject: [株式会社テスト]お問い合わせ
+ auto_reply_subject: [株式会社テスト]お問い合わせありがとうございます
+ auto_reply_name: 株式会社テスト
+ error_date: は存在する日付で入力してください。
View
@@ -9,5 +9,6 @@
*/
require_once 'lib/TransmitMail.php';
-$tm = new TransmitMail('config/config.yml');
+require_once 'lib/exTransmitMail.php';
+$tm = new exTransmitMail('config/config.yml');
$tm->run();
View
@@ -412,6 +412,22 @@
</tr>
</table>
</div>
+ <div class="section">
+ <h3>入力オプションの追加実装</h3>
+ <p>存在する日付かのチェック</p>
+ <table width="100%" class="alpha">
+ <tr>
+ <th width="300">日付</th>
+ <td>
+ <input type="date" name="日付" value="{$日付}" class="middle">
+ <input type="hidden" name="date[]" value="日付">
+ {if:$date.日付}
+ <div class="error"><em>{$date.日付}</em></div>
+ {/if:$date.日付}
+ </td>
+ </tr>
+ </table>
+ </div>
<div class="center"><input type="submit" value="入力内容を確認する"></div>
</form>
</div>
@@ -0,0 +1,73 @@
+<?php
+/**
+ * exTransmitMail クラス
+ *
+ * @package TransmitMail
+ * @license MIT License
+ * @copyright TAGAWA Takao, dounokouno@gmail.com
+ * @link https://github.com/dounokouno/TransmitMail
+ */
+
+class exTransmitMail extends TransmitMail
+{
+ public $exclusion_item = '[
+ "x",
+ "y",
+ "page",
+ "required",
+ "hankaku",
+ "hankaku_eisu",
+ "hankaku_eiji",
+ "num",
+ "num_hyphen",
+ "hiragana",
+ "zenkaku_katakana",
+ "zenkaku",
+ "zenkaku_all",
+ "email",
+ "match",
+ "len",
+ "url",
+ "num_range",
+ "file",
+ "file_remove",
+ "file_required",
+ "date"
+ ]';
+
+ /**
+ * 入力内容をチェックのあとの処理
+ */
+ public function afterCheckInput()
+ {
+ // 日付チェック
+ if (isset($this->post['date'])) {
+ foreach ($this->post['date'] as $value) {
+ $this->tpl->set("date.$value", false);
+
+ if (!empty($this->post[$value])) {
+ if (!$this->isDate($this->post[$value])) {
+ $this->tpl->set("date.$value", $this->h($value . $this->config['error_date']));
+ $this->global_errors[] = $this->h($value . $this->config['error_date']);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 存在する日付の判別
+ *
+ * @param string $string
+ * @return boolean
+ */
+ public function isDate($string)
+ {
+ $array = explode('-', $string);
+ $year = isset($array[0]) ? $array[0] : null;
+ $month = isset($array[1]) ? $array[1] : null;
+ $day = isset($array[2]) ? $array[2] : null;
+
+ return checkdate($month, $day, $year);
+ }
+}

0 comments on commit a9d8935

Please sign in to comment.