addElement('text', 'name', 'お名前', array('maxlength' => 80, 'class' => '')); $form->addElement('text', 'furigana', 'ふりがな', array('maxlength' => 80, 'class' => '')); $form->addElement('text', 'tel', '電話番号', array('maxlength' => 80, 'class' => '')); $form->addElement('text', 'mail', 'メールアドレス', array('maxlength' => 80, 'class' => '')); $shikaku[] = $form->createElement('text', 'year', '年', array('class' => 'form_shikaku firstchild')); $shikaku[] = $form->createElement('text', 'month', '月', array('class' => 'form_shikaku')); $shikaku[] = $form->createElement('text', 'day', '日', array('class' => 'form_shikaku')); $form->addGroup($shikaku, 'shikaku', '薬剤師資格取得日(取得予定日)', ''); $kibou_arr = array ( "full" => '正社員', "part" => 'パート', "care" => 'ケアマネジャー' ); /* foreach ($kibou_arr as $key => $value) { $kibou[] = $kibou[] = $form->createElement('radio', null, null, $value, $key, array('class' => 'form_kibou')); } */ $kibou[] = $form->createElement('radio', null, null, '正社員', 'full', array('class' => 'form_kibou firstchild')); $kibou[] = $form->createElement('radio', null, null, 'パート', 'part', array('class' => 'form_kibou')); $kibou[] = $form->createElement('radio', null, null, 'ケアマネジャー', 'care', array('class' => 'form_kibou')); $form->addGroup($kibou, 'kibou', '採用希望', ''); $form->addElement('textarea', 'message', 'ご質問・お問合せ内容:', array('class' => 'form_naiyou')); //HTML_QuickForm::registerRule("zenkakuCheck", "callback", "zenkakuCheck"); //HTML_QuickForm::registerRule("zenkanaCheck", "callback", "zenkanaCheck"); //HTML_QuickForm::registerRule("hankanaCheck", "callback", "hankanaCheck"); //HTML_QuickForm::registerRule("numberCheck", "callback", "numberCheck"); HTML_QuickForm::registerRule("htmlTagCheck", "callback", "htmlTagCheck"); $form->addRule('name', '必須項目', 'required', NULL); $form->addRule('name', 'タグ使用不可', 'htmlTagCheck', NULL, "server"); $form->addRule('furigana', '必須項目', 'required', NULL); $form->addRule('furigana', 'タグ使用不可', 'htmlTagCheck', NULL, "server"); $form->addRule('tel', 'タグ使用不可', 'htmlTagCheck', NULL, "server"); $form->addRule('mail', '必須項目', 'required', NULL); $form->addRule('mail', '不正な形式です', 'email', NULL); $form->addGroupRule('shikaku', '必須項目', 'required', NULL); $form->addGroupRule('shikaku', 'タグ使用不可', 'htmlTagCheck', NULL, "server"); $form->addRule('kibou', '必須項目', 'required', NULL); $form->addRule('message', 'タグ使用不可', 'htmlTagCheck', NULL, "server"); /* フィルター適用 */ $form->applyFilter('__ALL__', 'trim'); //$form->applyFilter('__ALL__', 'htmlentities'); //$form->applyFilter('__ALL__', 'addslashes'); //$form->applyFilter('__ALL__', 'escapeshellcmd'); /* 出力分岐処理 */ $template = basename($_SERVER['SCRIPT_NAME'], ".php") . ".tpl"; $title = ''; if ($form->validate()) { if (isset($_POST["submit"]["submit"])) { /* 確認画面 */ $title = '確認画面|'; display_confirm($form); } elseif (isset($_POST["submit"]["done"])) { /* 完了画面 */ if ($_SESSION['ticket'] == $_POST['session_ticket']) { /* 正常終了 */ unset($_SESSION['ticket']); $form->process('send_email', false); $url = 'complete.html'; header("Location: {$url}"); } else { /* 二重投稿エラー */ $url = 'error.html'; header("Location: {$url}"); } } else { display_form($form); } } else { display_form($form); } /* 出力処理 */ $renderer->setErrorTemplate('{{if $error}}{{$error}}{{/if}}'); //$renderer->setRequiredTemplate('{{if $error}}{{$label}}{{else}}{{$label}}{{/if}}{{if $required}} {{/if}}'); $renderer->setRequiredTemplate('{{if $error}}{{$label}}{{else}}{{$label}}{{/if}}'); $smarty->assign('title', $title); //if ($params) $form->_attributes["action"] .= '?mode=' . $params; $form->accept($renderer); $smarty->assign('form', $renderer->toArray()); $smarty->display($template); /* フォーム出力 */ function display_form(&$form) { global $smarty; $_SESSION['ticket'] = md5(mt_rand()); $smarty->assign("session_ticket", ''); $buttons[] = $form->createElement('image', 'submit', '../../cmn/img/page/form/form_btn_submit.png', array('alt' => '確認', 'class' => 'form_btn_submit')); //$buttons[] = $form->createElement('image', 'reset', './images/btn_reset.jpg', array('alt'=>'リセットする','onclick'=>'this.form.reset(); return false;')); $form->addGroup($buttons, "submit",'',''); } /* 確認画面出力 */ function display_confirm(&$form) { global $smarty; $smarty->assign("session_ticket", ''); $buttons[] = $form->createElement('image', 'return', '../../cmn/img/page/form/form_btn_check.png', array('alt'=>'修正', 'class' => 'form_btn_check')); $buttons[] = $form->createElement('image', 'done', '../../cmn/img/page/form/form_btn_submit.png', array('alt' => '送信', 'class' => 'form_btn_submit')); $form->addGroup($buttons, "submit",'',''); $form->freeze(); } /* 返信メール送信 */ function send_email($values) { global $from_address, $from_name, $user_title, $admin_address, $admin_title, $kibou_arr; $from = $from_address; $to = $values['mail']; $date = date("Y/m/d H:i:s"); $name = mb_convert_kana($values['name'], "KV", 'UTF-8'); $furigana = mb_convert_kana($values['furigana'], "KV", 'UTF-8'); $tel = mb_convert_kana($values['tel'], "KV", 'UTF-8'); $mail = mb_convert_kana($values['mail'], "KV", 'UTF-8'); $shikaku = mb_convert_kana($values['shikaku']['year'], "KV", 'UTF-8') . '年' . mb_convert_kana($values['shikaku']['month'], "KV", 'UTF-8') . '月' . mb_convert_kana($values['shikaku']['day'], "KV", 'UTF-8') .'日'; $kibou = mb_convert_kana($values['kibou'], "KV", 'UTF-8'); $kibou = $kibou_arr[$kibou]; $message = mb_convert_kana($values['message'], "KV", 'UTF-8'); $user_smarty = new MySmarty(); $user_smarty->assign("name", $name); $user_smarty->assign("furigana", $furigana); $user_smarty->assign("tel", $tel); $user_smarty->assign("mail", $mail); $user_smarty->assign("shikaku", $shikaku); $user_smarty->assign("kibou", $kibou); $user_smarty->assign("message", $message); $user_mail = $user_smarty->fetch("user_mail.tpl"); $admin_smarty = new MySmarty(); $admin_smarty->assign("name", $name); $admin_smarty->assign("furigana", $furigana); $admin_smarty->assign("tel", $tel); $admin_smarty->assign("mail", $mail); $admin_smarty->assign("shikaku", $shikaku); $admin_smarty->assign("kibou", $kibou); $admin_smarty->assign("message", $message); $admin_mail = $admin_smarty->fetch("admin_mail.tpl"); mb_language('Japanese'); $recipients = mb_encode_mimeheader(mb_convert_encoding($name . '様', 'ISO-2022-JP')) . '<' . $to . '>'; $headers = array( 'Return-Path' => $from, 'From' => mb_encode_mimeheader(mb_convert_encoding($from_name, 'ISO-2022-JP')) . '<' . $from . '>', 'To' => mb_encode_mimeheader(mb_convert_encoding($name . '様', 'ISO-2022-JP')) . '<' . $to . '>', 'Subject' => mime($user_title),//mb_encode_mimeheader(mb_convert_encoding($user_title, 'ISO-2022-JP'), 'JIS', 'B', "\n"), 'Mime-Version' => '1.0', 'Content-Type' => 'text/plain; charset="iso-2022-jp"', 'Content-Transfer-Encoding' => '7bit', ); $recipients2 = $admin_address; $_arr = split(",", $admin_address); $admin_address = $_arr[0]; $headers2 = array( 'Return-Path' => $from, 'From' => mb_encode_mimeheader(mb_convert_encoding($from_name, 'ISO-2022-JP')) . '<' . $from . '>', 'To' => $admin_address, 'Subject' => mime($admin_title),//mb_encode_mimeheader(mb_convert_encoding($admin_title, 'ISO-2022-JP'), 'JIS', 'B', "\n"), 'Mime-Version' => '1.0', 'Content-Type' => 'text/plain; charset="iso-2022-jp"', 'Content-Transfer-Encoding' => '7bit', ); $user_mail = mb_convert_encoding($user_mail, 'ISO-2022-JP'); $admin_mail = mb_convert_encoding($admin_mail, 'ISO-2022-JP'); $mail_object =& Mail::factory('mail'); if (!$mail_object->send($recipients, $headers, $user_mail) || !$mail_object->send($recipients2, $headers2, $admin_mail)) { $url = 'error.html'; header("Location: {$url}"); } } function mime($str) { $str = mb_convert_encoding($str, "ISO-2022-JP","UTF-8"); ini_set('mbstring.internal_encoding', 'ISO-2022-JP'); $str = mb_encode_mimeheader($str, "ISO-2022-JP"); ini_set('mbstring.internal_encoding', 'UTF-8'); return $str; } ?>