質問編集履歴
9
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -832,7 +832,11 @@
|
|
832
832
|
|
833
833
|
|
834
834
|
|
835
|
+
・registaration_form.php (登録フォーム) 一部抜粋
|
836
|
+
|
837
|
+
|
838
|
+
|
835
|
-
|
839
|
+
上の確認フォームからエラーメッセージをリダイレクトで受け取っています。
|
836
840
|
|
837
841
|
|
838
842
|
|
@@ -840,8 +844,6 @@
|
|
840
844
|
|
841
845
|
registration_confirm.php でエラーがあれば registration_form.php にリダイレクト
|
842
846
|
|
843
|
-
|
844
|
-
|
845
847
|
```
|
846
848
|
|
847
849
|
// エラーメッセージ
|
8
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -829,3 +829,37 @@
|
|
829
829
|
|
830
830
|
|
831
831
|
```
|
832
|
+
|
833
|
+
|
834
|
+
|
835
|
+
registaration_form.php (登録フォーム) 一部抜粋 上の確認フォームからエラーメッセージをリダイレクトで受け取っています。
|
836
|
+
|
837
|
+
|
838
|
+
|
839
|
+
順番は registration_form.php → registration_confirm.php
|
840
|
+
|
841
|
+
registration_confirm.php でエラーがあれば registration_form.php にリダイレクト
|
842
|
+
|
843
|
+
|
844
|
+
|
845
|
+
```
|
846
|
+
|
847
|
+
// エラーメッセージ
|
848
|
+
|
849
|
+
if (isset($_SESSION['result'])) {
|
850
|
+
|
851
|
+
|
852
|
+
|
853
|
+
if (count(array($_SESSION['result'])) >= 1) {
|
854
|
+
|
855
|
+
|
856
|
+
|
857
|
+
$result = $_SESSION['result'];
|
858
|
+
|
859
|
+
|
860
|
+
|
861
|
+
}
|
862
|
+
|
863
|
+
}
|
864
|
+
|
865
|
+
```
|
7
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -610,6 +610,14 @@
|
|
610
610
|
|
611
611
|
|
612
612
|
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
```
|
618
|
+
|
619
|
+
|
620
|
+
|
613
621
|
registration_confirm.php 一部抜粋
|
614
622
|
|
615
623
|
|
6
誤字
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
5
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -616,6 +616,8 @@
|
|
616
616
|
|
617
617
|
```
|
618
618
|
|
619
|
+
|
620
|
+
|
619
621
|
// POST時
|
620
622
|
|
621
623
|
if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') == 'POST') {
|
4
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -612,6 +612,8 @@
|
|
612
612
|
|
613
613
|
registration_confirm.php 一部抜粋
|
614
614
|
|
615
|
+
|
616
|
+
|
615
617
|
```
|
616
618
|
|
617
619
|
// POST時
|
3
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -435,3 +435,385 @@
|
|
435
435
|
|
436
436
|
|
437
437
|

|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
validation.php
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
```
|
448
|
+
|
449
|
+
<?php
|
450
|
+
|
451
|
+
require_once('../config/config.php');
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
// バリデーションクラス
|
456
|
+
|
457
|
+
class Validation {
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
// コンストラクタ(construct)
|
462
|
+
|
463
|
+
function check_Validation($input_control = [], $input_data = []) {
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
$result = []; //チェック結果配列
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
foreach ($input_control as $control_name => $info) {
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
// 入力情報が存在するか
|
476
|
+
|
477
|
+
if (array_key_exists($control_name, $input_data)) {
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
$value = $input_data[$control_name];
|
482
|
+
|
483
|
+
$rules = explode("|", $info["rule"]); // バリデーションルールの引き出し
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
foreach ($rules as $r) { // 指定されたルールをループ
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
$rule = explode("-", $r); // ルール設定の切り出し
|
492
|
+
|
493
|
+
$rule_name = $rule[0]; // ルール名
|
494
|
+
|
495
|
+
$rule_setting = $rule[1]; // ルール設定
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
switch ($rule_name) {
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
// 入力が空の場合
|
508
|
+
|
509
|
+
case "empty":
|
510
|
+
|
511
|
+
if ($this->empty_check($value)) {
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
$result[$control_name][] = $info["name"].'を入力してください。';
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
}
|
520
|
+
|
521
|
+
break;
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
// 最大文字数のチェック
|
526
|
+
|
527
|
+
case "max":
|
528
|
+
|
529
|
+
if ($this->max_check($value, $rule_setting)) {
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
$result[$control_name][] = $info["name"].'は'.$rule_setting.'文字以内で入力してください。';
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
}
|
538
|
+
|
539
|
+
break;
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
}
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
}
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
}
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
}
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
return $result;
|
564
|
+
|
565
|
+
|
566
|
+
|
567
|
+
}
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
// 空のチェック
|
580
|
+
|
581
|
+
public function empty_check($value = "") {
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
return empty($value);
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
}
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
// 入力文字数のチェック
|
594
|
+
|
595
|
+
public function max_check($value = "", $max = 60) {
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
return mb_strlen($value) > $max;
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
}
|
604
|
+
|
605
|
+
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
}
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
registration_confirm.php 一部抜粋
|
614
|
+
|
615
|
+
```
|
616
|
+
|
617
|
+
// POST時
|
618
|
+
|
619
|
+
if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') == 'POST') {
|
620
|
+
|
621
|
+
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
$_SESSION["name"] = filter_input(INPUT_POST, 'name');
|
626
|
+
|
627
|
+
$_SESSION["email"] = filter_input(INPUT_POST, 'email');
|
628
|
+
|
629
|
+
$_SESSION["password"] = filter_input(INPUT_POST, 'password');
|
630
|
+
|
631
|
+
$_SESSION["tel"] = filter_input(INPUT_POST, 'tel');
|
632
|
+
|
633
|
+
$_SESSION["prefectures"] = filter_input(INPUT_POST, 'prefectures');
|
634
|
+
|
635
|
+
$_SESSION["hobby"] = filter_input(INPUT_POST, 'hobby', FILTER_DEFAULT,FILTER_REQUIRE_ARRAY);
|
636
|
+
|
637
|
+
$_SESSION["gender"] = filter_input(INPUT_POST, 'gender');
|
638
|
+
|
639
|
+
$_SESSION["contact"] = filter_input(INPUT_POST, 'contact');
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
$name = $_SESSION["name"];
|
644
|
+
|
645
|
+
$email = $_SESSION["email"];
|
646
|
+
|
647
|
+
$password = $_SESSION["password"];
|
648
|
+
|
649
|
+
$tel = $_SESSION["tel"];
|
650
|
+
|
651
|
+
$prefectures = $_SESSION["prefectures"];
|
652
|
+
|
653
|
+
$hobby = $_SESSION["hobby"];
|
654
|
+
|
655
|
+
$gender = $_SESSION["gender"];
|
656
|
+
|
657
|
+
$contact = $_SESSION["contact"];
|
658
|
+
|
659
|
+
|
660
|
+
|
661
|
+
|
662
|
+
|
663
|
+
|
664
|
+
|
665
|
+
// 対象コントロール→バリデーションルール
|
666
|
+
|
667
|
+
$input_control = [
|
668
|
+
|
669
|
+
|
670
|
+
|
671
|
+
"name" => [
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
"name" => "氏名",
|
676
|
+
|
677
|
+
"rule" => "empty|max-60"
|
678
|
+
|
679
|
+
|
680
|
+
|
681
|
+
],
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
"tel" => [
|
686
|
+
|
687
|
+
|
688
|
+
|
689
|
+
"name" => "電話番号",
|
690
|
+
|
691
|
+
"rule" => "empty|min-10|-|halfSize"
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
],
|
696
|
+
|
697
|
+
|
698
|
+
|
699
|
+
"password" => [
|
700
|
+
|
701
|
+
|
702
|
+
|
703
|
+
"name" => "パスワード",
|
704
|
+
|
705
|
+
"rule" => "empty|min-8"
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
],
|
710
|
+
|
711
|
+
|
712
|
+
|
713
|
+
//・・・・以下、対象の入力項目とルールを定義
|
714
|
+
|
715
|
+
|
716
|
+
|
717
|
+
];
|
718
|
+
|
719
|
+
|
720
|
+
|
721
|
+
$result = new Validation($input_control, $_SESSION);
|
722
|
+
|
723
|
+
|
724
|
+
|
725
|
+
if (count($result) > 0) {
|
726
|
+
|
727
|
+
|
728
|
+
|
729
|
+
$_SESSION['result'] = $result;
|
730
|
+
|
731
|
+
header("location: registration_form.php");
|
732
|
+
|
733
|
+
|
734
|
+
|
735
|
+
} else {
|
736
|
+
|
737
|
+
|
738
|
+
|
739
|
+
$result = array();
|
740
|
+
|
741
|
+
|
742
|
+
|
743
|
+
}
|
744
|
+
|
745
|
+
|
746
|
+
|
747
|
+
|
748
|
+
|
749
|
+
|
750
|
+
|
751
|
+
}
|
752
|
+
|
753
|
+
|
754
|
+
|
755
|
+
|
756
|
+
|
757
|
+
|
758
|
+
|
759
|
+
|
760
|
+
|
761
|
+
//
|
762
|
+
|
763
|
+
// Twig
|
764
|
+
|
765
|
+
//
|
766
|
+
|
767
|
+
|
768
|
+
|
769
|
+
// Composerで作成されたautoload.phpを読み込む
|
770
|
+
|
771
|
+
require_once ('../vendor/autoload.php');
|
772
|
+
|
773
|
+
// Twig_Loader_Filesystem と Twig instance の生成を読み込む
|
774
|
+
|
775
|
+
require_once('../config/twig.php');
|
776
|
+
|
777
|
+
|
778
|
+
|
779
|
+
|
780
|
+
|
781
|
+
// render
|
782
|
+
|
783
|
+
echo $twig->render('registration_confirm.html', array (
|
784
|
+
|
785
|
+
|
786
|
+
|
787
|
+
'name' => $name,
|
788
|
+
|
789
|
+
'email' => $email,
|
790
|
+
|
791
|
+
'password' => $password,
|
792
|
+
|
793
|
+
'tel' => $tel,
|
794
|
+
|
795
|
+
'prefectures' => $prefectures,
|
796
|
+
|
797
|
+
'hobby' => $hobby,
|
798
|
+
|
799
|
+
'gender' => $gender,
|
800
|
+
|
801
|
+
'contact' => $contact,
|
802
|
+
|
803
|
+
|
804
|
+
|
805
|
+
'result' => $result,
|
806
|
+
|
807
|
+
'string' => $string,
|
808
|
+
|
809
|
+
|
810
|
+
|
811
|
+
|
812
|
+
|
813
|
+
)
|
814
|
+
|
815
|
+
);
|
816
|
+
|
817
|
+
|
818
|
+
|
819
|
+
```
|
2
バグ画像
test
CHANGED
File without changes
|
test
CHANGED
@@ -431,3 +431,7 @@
|
|
431
431
|
|
432
432
|
|
433
433
|
```
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+

|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -168,6 +168,20 @@
|
|
168
168
|
|
169
169
|
下記のようにまとめてみました。
|
170
170
|
|
171
|
+
まとめたやつは
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```php
|
176
|
+
|
177
|
+
require_once('./validation.php');
|
178
|
+
|
179
|
+
name_validation();
|
180
|
+
|
181
|
+
```
|
182
|
+
|
183
|
+
みたいに使っていこうと思っています。
|
184
|
+
|
171
185
|
ですが、1個1個メソッドを作るのがとてもめんどうなのですが、
|
172
186
|
|
173
187
|
1つ1つメソッドを作る以外に、もっとまとめられる方法はありますか?
|