問題
- codeigniterを用いた送信フォームを作成しています。
- post通信で送った値(form_step1.php)をコントローラの配列に格納してその値をview(thanks.php)に返すことで表示したいと考えております。
- しかしうまいこといきません、もしよろしければどこが間違っているのか教えていただけると幸いです。
ソースコード
controllers/form.php
1<?php 2defined('BASEPATH') OR exit('No direct script access allowed'); 3 4class Form extends CI_Controller { 5 public function index() 6 { 7 $this->load->helper("array"); 8 $this->loa->helper("form"); 9 $this->load->library('form_validation'); 10 $this->form_validation->set_rules("name","名前","required"); 11 $this->form_validation->set_rules('email', 'メールアドレス', 'required'); 12 $this->form_validation->set_rules('email2', 'メールアドレス後半', 'required'); 13 $this->form_validation->set_rules("choice","選択","required"); 14 15 $this->form_validation->set_message("required","%sが入力されていません。"); 16 17 18 $name = $this->input->post("name"); 19 $email = $this->input->post("email"); 20 $email2 = $this->input->post("email2"); 21 $choice = $this->input->post("choice"); 22 23 $data = array( 24 "name" => $name, 25 "email" => $email, 26 "email2" => $email2, 27 "choice" => $choice, 28 ); 29 30 if($this->form_validation->run() == FALSE) 31 { 32 $this->load->view("form_step1"); 33 } 34 else{ 35 $this->load->view("thanks",$data); 36 } 37 } 38}
views/form_step1.php
1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <meta charset="UTF-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <title>入力フォーム</title> 8</head> 9<body> 10 11<h1>Step1</h1> 12 13<?php echo validation_errors(); ?> 14<?php echo form_open('/form/thanks'); ?> 15 <fieldset> 16 <p class="attention">テスト送信フォーム</p> 17 <table> 18 <tbody> 19 <tr> 20 <th>名前: </th> 21 <td><input type="text" id="name" name="name" value="" /></td> 22 </tr> 23 24 <tr> 25 <th>メール: </th> 26 <td><input type="text" id="email1" name="email" value="" /> 27 @ 28 <input type="text" name="email2" value="" /></td> 29 </tr> 30 <tr> 31 <th>メッセージ記入欄: </th> 32 <td> 33 <textarea name="textarea" id="textarea" cols="100" rows="10"></textarea> 34 </td> 35 </tr> 36 <tr> 37 <th>ラジオボックス: </th> 38 <td> 39 <label for="yes"><input type="radio" id="yes" name="choice" value="yes" />はい</label> 40 <label for="no"><input type="radio" id="no" name="choice" value="no" />いいえ</label> 41 </td> 42 </tr> 43 44 </tbody> 45 </table> 46 </fieldset> 47 <p class="submit"><input type="submit" value="提出"/></p> 48</form> 49 50</body> 51</html>
views/thanks.php
1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <meta charset="UTF-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <title>Document</title> 8</head> 9<body> 10<html> 11 <body> 12 13 <tr> 14 <th>名前: </th> 15 <td><?php $name ?></td> 16 </tr> 17 <tr> 18 <th>メール: </th> 19 <td><?php $email ?>@<?php $email2 ?></td> 20 </tr> 21 <tr> 22 <th>ラジオボックス: </th> 23 <td><?php $choice ?></td> 24 </tr> 25 26 27 </body> 28</html> 29</body> 30</html>

あなたの回答
tips
プレビュー