Skip to content

Instantly share code, notes, and snippets.

@kohki-shikata
Created August 21, 2021 16:29
Show Gist options
  • Save kohki-shikata/9f7f448240125e174da43bbd5f6c4d9a to your computer and use it in GitHub Desktop.
Save kohki-shikata/9f7f448240125e174da43bbd5f6c4d9a to your computer and use it in GitHub Desktop.
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
// ヘルパー読み込み
$form = Core::make('helper/form');
if($confirm == true) {
// 確認画面
?>
<style>
.screen_active p {
text-align: center;
border: 1px solid #e4980e;
background: #ffebd2;
color: #000;
padding: .5em;
}
.screen_future p {
color: #bbb;
border: 1px solid #bbb;
text-align: center;
padding: .5em;
}
.screen_disabled p {
color: #999;
background: #ddd;
text-decoration: line-through;
text-align: center;
padding: .5em;
}
.next_arrow:after {
content: '→';
color: #bbb;
position: absolute;
top: 50%;
transform: translateY(calc(-50% - 4px));
right: -9px;
}
@media (max-width: 990px) {
.next_arrow:after {
content: '↓';
color: #bbb;
position: absolute;
bottom: -11px;
left: 50%;
transform: initial;
top: initial;
transform: translateX(calc(-50% + 82px));
}
}
</style>
<div class="container" style="margin-bottom: 30px;">
<div class="row">
<div class="col-md-4 screen_disabled next_arrow">
<p>入力画面</p>
</div>
<div class="col-md-4 screen_active next_arrow">
<p>確認画面</p>
</div>
<div class="col-md-4 screen_future">
<p>完了画面</p>
</div>
</div>
</div>
<p>入力された内容は以下の通りです。問題なければ、送信ボタンを押してください</p>
<style>
dd { margin-bottom: .5em;}
</style>
<dl>
<dt>お名前</dt>
<dd><?php echo $post['contact_name'];?></dd>
<dt>企業・団体名</dt>
<dd><?php echo $post['contact_company'];?></dd>
<dt>メールアドレス</dt>
<dd><?php echo $post['contact_email'];?></dd>
<?php if(is_null($post['contact_phone'])): ?>
<dt>電話番号</dt>
<dd><?php echo $post['contact_phone'];?></dd>
<?php endif;?>
<dt>お問い合わせの種類</dt>
<dd><?php echo $post['contact_type'];?></dd>
<dt>お問い合わせ本文</dt>
<dd><?php echo $post['contact_body'];?></dd>
<dt>プライバシーポリシーへの同意</dt>
<dd>同意する</dd>
<form action="<?php echo $view->action('send')?>" method="POST">
<?php
echo $form->hidden('contact_name', $post['contact_name']);
echo $form->hidden('contact_company', $post['contact_company']);
echo $form->hidden('contact_email', $post['contact_email']);
echo $form->hidden('contact_phone', $post['contact_phone']);
echo $form->hidden('contact_type', $post['contact_type']);
echo $form->hidden('contact_body', $post['contact_body']);
echo $form->hidden('contact_privacy', 'プライバシーポリシーに同意する');
?>
<a href="#" onClick="history.back(); return false;">戻る</a>
<?php echo $form->submit('submit', '送信', array('class' => 'btn-primary'));?>
</form>
</dl>
<?php }
if(isset($response)) {
// コントローラー処理完了後の処理(サンクスメッセージなど)
?>
<style>
.screen_active p {
text-align: center;
border: 1px solid #e4980e;
background: #ffebd2;
color: #000;
padding: .5em;
}
.screen_disabled p {
color: #999;
background: #ddd;
text-decoration: line-through;
text-align: center;
padding: .5em;
}
.next_arrow:after {
content: '→';
color: #bbb;
position: absolute;
top: 50%;
transform: translateY(calc(-50% - 4px));
right: -9px;
}
@media (max-width: 990px) {
.next_arrow:after {
content: '↓';
color: #bbb;
position: absolute;
bottom: -11px;
left: 50%;
transform: initial;
top: initial;
transform: translateX(calc(-50% + 82px));
}
}
</style>
<div class="container" style="margin-bottom: 30px;">
<div class="row">
<div class="col-md-4 screen_disabled next_arrow">
<p>入力画面</p>
</div>
<div class="col-md-4 screen_disabled next_arrow">
<p>確認画面</p>
</div>
<div class="col-md-4 screen_active">
<p>完了画面</p>
</div>
</div>
</div>
<p>UPLIFTにお問い合わせいただきありがとうございました。</p>
<p>入力されたメールアドレス宛に、確認のメールを送信しました。<p>
<p>1営業日以内にご返答いたします。しばらくお待ちください。</p>
<p><a href="/">トップページへ戻る</a></p>
<?php
} else {
// フォーム表示
if(!isset($confirm)) { ?>
<style>
#contact_name, #contact_company, #contact_email, #contact_phone { width: 25em; }
textarea.form-control.body { height: 20em !important; max-width: 40em !important;}
.control-label {
padding-right: 4em;
position: relative;
}
.required:after {
content: '必須';
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%);
background: #e03232;
padding: .15em .3em;
color: #fff;
font-size: 70%;
border-radius: 4px;
font-weight: bold;
}
.any:after {
content: '任意';
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%);
background: #dadada;
padding: .15em .3em;
color: #444;
font-size: 70%;
border-radius: 4px;
}
.screen_active p {
text-align: center;
border: 1px solid #e4980e;
background: #ffebd2;
color: #000;
padding: .5em;
}
.screen_future p {
color: #bbb;
border: 1px solid #bbb;
text-align: center;
padding: .5em;
}
.next_arrow:after {
content: '→';
color: #bbb;
position: absolute;
top: 50%;
transform: translateY(calc(-50% - 4px));
right: -9px;
}
@media (max-width: 990px) {
.next_arrow:after {
content: '↓';
color: #bbb;
position: absolute;
bottom: -11px;
left: 50%;
transform: initial;
top: initial;
transform: translateX(calc(-50% + 82px));
}
}
.privacy-policy-window {
border: 1px solid #ddd;
padding: 15px;
font-size: 85%;
height: 20em;
overflow-y: scroll;
margin-bottom: 1.5em;
}
</style>
<div class="container" style="margin-bottom: 30px;">
<div class="row">
<div class="col-md-4 screen_active next_arrow">
<p>入力画面</p>
</div>
<div class="col-md-4 screen_future next_arrow">
<p>確認画面</p>
</div>
<div class="col-md-4 screen_future">
<p>完了画面</p>
</div>
</div>
</div>
<form method="post" action="<?php echo $view->action('confirm')?>" class="form-horizontal">
<div class="form-group">
<?php echo $form->label('contact_name','お名前', array('class' => 'col-sm-3 control-label required')); ?>
<div class="col-sm-9">
<?php echo $form->text('contact_name', array('class' => 'form-control')); ?>
<?php if($error['name']): ?>
<div class="alert alert-danger">
<p><?php echo $error['name'];?></p>
</div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<?php echo $form->label('contact_company','企業・団体名', array('class' => 'col-sm-3 control-label required')); ?>
<div class="col-sm-9">
<?php echo $form->text('contact_company', array('class' => 'form-control')); ?>
<?php if($error['company']): ?>
<div class="alert alert-danger">
<p><?php echo $error['company'];?></p>
</div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<?php echo $form->label('contact_email','メールアドレス', array('class' => 'col-sm-3 control-label required')); ?>
<div class="col-sm-9">
<?php echo $form->email('contact_email', array('class' => 'form-control')); ?>
<?php if($error['email']): ?>
<div class="alert alert-danger">
<p><?php echo $error['email'];?></p>
</div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<?php echo $form->label('contact_phone','電話番号', array('class' => 'col-sm-3 control-label any')); ?>
<div class="col-sm-9">
<?php echo $form->telephone('contact_phone', array('class' => 'form-control')); ?>
</div>
</div>
<div class="form-group">
<div class="col-sm-3 control-label required">
<p><b>お問い合わせの種類</b></p>
</div>
<div class="col-sm-9">
<div class="radio">
<label>
<?php echo $form->radio('contact_type','ソリューションのお問い合わせ'); ?> ソリューションのお問い合わせ
</label>
</div>
<div class="radio">
<label>
<?php echo $form->radio('contact_type','取材のお問い合わせ'); ?> 取材のお問い合わせ
</label>
</div>
<div class="radio">
<label>
<?php echo $form->radio('contact_type','UPLIFTへのセールス・営業'); ?> UPLIFTへのセールス・営業・協業のお誘い
</label>
</div>
<div class="radio">
<label>
<?php echo $form->radio('contact_type','その他'); ?> その他
</label>
</div>
<?php if($error['type']): ?>
<div class="alert alert-danger">
<p><?php echo $error['type'];?></p>
</div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<?php echo $form->label('contact_body', 'お問い合わせ本文', array('class' => 'col-sm-3 required'));?>
<div class="col-sm-9">
<?php echo $form->textarea('contact_body', array('class' => 'form-control body'));?>
<?php if($error['body']): ?>
<div class="alert alert-danger">
<p><?php echo $error['body'];?></p>
</div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<div class="col-sm-3 control-label required">
<p><b>プライバシーポリシー同意</b></p>
</div>
<div class="col-sm-9">
<div class="privacy-policy-window">
<?php
$stack = Stack::getByName('プライバシーポリシー');
$stack->display();
?>
</div>
</div>
<div class="col-sm-9 col-sm-offset-3">
<label>
<?php echo $form->checkbox('contact_privacy', 'プライバシーポリシー同意済み');?> プライバシーポリシーに同意する。
</label>
<?php if($error['privacy']): ?>
<div class="alert alert-danger">
<p><?php echo $error['privacy'];?></p>
</div>
<?php endif;?>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-4">
<?php echo $form->submit('submit', '確認', array('class' => 'btn-primary'));?>
</div>
</div>
</form>
<?php
}
}
?>
<?php
namespace Application\Block\ExternalForm\Form\Controller;
use Concrete\Core\Controller\AbstractController;
use Core;
use UserInfo;
class Contact extends AbstractController {
public function action_confirm($bID = false) {
if ($this->bID == $bID) {
// validation/form ヘルパーを呼び出し
$email = Core::make('helper/validation/strings');
// postデータを登録
$post = $this->post();
// 登録内容の検証
$errormsg = array();
if($this->post('contact_type') == null){
$errormsg['type'] = 'いずれか選択してください。';
}
if($this->post('contact_name') == null){
$errormsg['name'] = 'お名前は必須項目です。必ず入力してください。';
}
if($this->post('contact_company') == null){
$errormsg['company'] = '企業・団体名は必須項目です。必ず入力してください。';
}
if($this->post('contact_body') == null){
$errormsg['body'] = 'お問い合わせ本文は必須項目です。必ず入力してください。';
}
if($this->post('contact_privacy') == null){
$errormsg['privacy'] = 'プライバシーポリシーへの同意は必須項目です。';
}
if(!$email->email($this->post('contact_email'))){
$errormsg['email'] = '有効なメールアドレスを入力してください。';
}
if($errormsg){
$this->set('error', $errormsg);
}
else{
$this->set('post', $post);
$this->set('confirm', true);
return true;
}
}
}
public function action_send($bID = false) {
if ($this->bID == $bID) {
$post = $this->post();
$this->set('post', $post);
$mh = Core::make('helper/mail');
$adminUserInfo = UserInfo::getByID(USER_SUPER_ID);
$mh->bcc($adminUserInfo->getUserEmail());//サイトオーナーへbcc送信
$mh->from($adminUserInfo->getUserEmail(), 'UPLIFT公式サイト');//メール送信元
$mh->to($this->post('contact_email'));//登録者への自動返信
//パラメータをゲット
$mh->addParameter('name', $this->post('contact_name'));
$mh->addParameter('email', $this->post('contact_company'));
$mh->addParameter('email', $this->post('contact_email'));
if($this->post('contact_phone')) {
$mh->addParameter('phone', $this->post('contact_email'));
}
$mh->addParameter('type', $this->post('contact_type'));
$mh->addParameter('contact_body', $this->post('contact_body'));
$mh->addParameter('privacy', $this->post('contact_privacy'));
$mh->load('contact_complete');//メールテンプレの読み込み
@$mh->sendMail();//メール送信
$this->set('response',true);//メールが送れた後の処理
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment