2017-02-07 10 views
1

ポスト変数がコントローラで受信されました。ポスト変数は、コードイグジットを使用してコントローラで受信されません

ビュー:loginhome.php

<?php 
//----------------------------------------------------------------------------- 
//       Including Header 
//----------------------------------------------------------------------------- 
$base = dirname(__FILE__); 
include($base . '/header.php'); 
?> 
<div class="login-wrap"> 
    <div class="login-html"> 
     <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">Sign In</label> 
     <input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">Sign Up</label> 
     <div class="login-form"> 
      <div class="sign-in-htm"> 
      <?php 
$attributes = array(
    'name' => 'login_form', 
    'id' => 'login_form', 
    'method' => 'POST' 
); 
echo form_open('VerifyLogin', $attributes); 
?> 

       <div class="group"> 
        <label for="user" class="label">Username</label> 

        <?php 
$data = array(
    'name' => 'user', 
    'id' => 'user', 
    'class' => 'input' 
); 
echo form_input($data); 
?> 
       </div> 
       <div class="group"> 
        <label for="pass" class="label">Password</label> 

        <?php 
$data = array(
    'name' => 'pass', 
    'id' => 'pass', 
    'class' => 'input' 
); 
echo form_password($data); 
?> 
       </div> 
       <div class="group"> 
        <input id="check" type="checkbox" class="check" checked> 
        <label for="check"><span class="icon"></span> Keep me Signed in here</label> 
       </div> 
       <div class="group"> 

        <?php 
$data = array(
    'name' => 'SignIn', 
    'id' => 'SignIn', 
    'value' => 'Sign In', 
    'class' => 'button' 
); 
echo form_submit($data); 
//echo anchor('forgotpassword', 'Forgot Password???', 'class="link-class"'); 
?> 
       </div> 

<?php 
echo form_close(); 
?> 

       <div class="hr"></div> 
       <div class="foot-lnk"> 
        <a href="#forgot">Forgot Password?</a> 
       </div> 
      </div> 
      <?php 
$attributes = array(
    'name' => 'sign-up_form', 
    'id' => 'sign-up_form', 
    'method' => 'GET' 
); 
echo form_open('RegisterUser', $attributes); 
?> 
      <div class="sign-up-htm"> 
       <div class="group"> 

        <label for="user" class="label">Name</label> 

        <?php 
$data = array(
    'id' => 'name', 
    'type' => 'text', 
    'class' => 'input' 
); 
echo form_input($data); 
?> 
       </div> 
       <div class="group"> 

        <label for="user" class="label">Username</label> 

        <?php 
$data = array(
    'id' => 'username', 
    'type' => 'text', 
    'class' => 'input' 
); 
echo form_input($data); 
?> 
       </div> 
       <div class="group"> 
        <label for="pass" class="label">Password</label> 
        <?php 
$data = array(
    'id' => 'password', 
    'type' => 'password', 
    'class' => 'input' 
); 
echo form_password($data); 
?> 
       </div> 
       <div class="group"> 
        <label for="pass" class="label">Repeat Password</label> 
        <?php 
$data = array(
    'id' => 'password', 
    'type' => 'password', 
    'class' => 'input' 
); 
echo form_password($data); 
?> 
       </div> 
       <div class="group"> 
        <label for="pass" class="label">Email Address</label> 

        <?php 
$data = array(
    'id' => 'email', 
    'type' => 'text', 
    'class' => 'input' 
); 
echo form_input($data); 
?></div> 
       <div class="group"> 


        <?php 
$data = array(
    'id' => 'submitButton', 
    'type' => 'submit', 
    'value' => 'request', 
    'class' => 'button' 
); 
echo form_submit($data); 
//echo form_close(); 
?> 

       </div> 

       <div class="hr"></div> 
       <div class="foot-lnk"> 
        <label for="tab-1"><a href='#Already'>Already Member?</a></label> 
       </div> 


     </div> 
     <?php 
echo form_close(); 
?> 
    </div> 

</div> 
<?php 
//----------------------------------------------------------------------------- 
//       Including Footer 
//----------------------------------------------------------------------------- 
$base = dirname(__FILE__); 
include($base . '/footer.php'); 
?> 

コントローラー:RegisterUser.php

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class RegisterUser extends CI_Controller { 

function __construct() 
{ 
    parent::__construct(); 
    $this->load->model('InsertUser','',TRUE); 
} 

function index() 
{ 
    echo 'Hello World123'; 
    //This method will have the credentials validation 
    $this->load->library('form_validation'); 
    $name = $this->input->post('name'); 
    $username = $this->input->post('username'); 
    $password = $this->input->post('password'); 
    $email = $this->input->post('email'); 
    echo 'User name: '.$username.'Password: '.$password; 
/* 
    $this->form_validation->set_rules('name', 'Name', 'required'); 
    $this->form_validation->set_rules('username', 'User Name', 'required'); 
    $this->form_validation->set_rules('password', 'Password', 'required'); 
    $this->form_validation->set_rules('email', 'E-Mail', 'required'); 
    //$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database'); 

    if($this->form_validation->run() == FALSE) 
    { 
    //Field validation failed. User redirected to login page 
    echo 'Something is not in format'; 
    $this->load->view('loginhome'); 
    } 
    else 
    { 
    //Go to private area 
     $this->insert_database(); 
     redirect('home', 'refresh'); 
    }*/ 
    //$this->insert_database(); 
     echo 'This is it'; 
} 

function insert_database() 
{ 
    //Field validation succeeded. Validate against database 
    $name = $this->input->post('name'); 
    $username = $this->input->post('username'); 
    $password = $this->input->post('password'); 
    $email = $this->input->post('email'); 
    echo $username.$password; 
    //query the database 
    $result = $this->InsertUser->form_insert($name,$username, $password,$email); 
    echo 'Inserted'; 
    if($result) 
    { 
    $sess_array = array(); 
    foreach($result as $row) 
    { 
     $sess_array = array(
     'id' => $row->user_id, 
     'username' => $row->user_name 
     ); 
     $this->session->set_userdata('logged_in', $sess_array); 
     echo 'logged-in'; 
    } 
    return TRUE; 
    } 
    else 
    { 
    $this->form_validation->set_message('check_database', 'Invalid username or password'); 
    echo 'log-in failed'; 
    return false; 
    } 
} 
} 
?> 

あなたがしても、httpリクエストのクエリに変化がない得るためにポストを変更しても。

サインインモジュールは正常に機能していますが、サインアップが機能していません。

私はignitorとphpを初めて使用しています。

答えて

3

変更方法GETあなたのフィールドは次のようにname属性を追加

<?php 
$attributes = array(
    'name' => 'sign-up_form', 
    'id' => 'sign-up_form', 
    'method' => 'POST' 
); 

そして

foreachのPOSTに...

$data = array(
    'name'=>'name', 
    'id' => 'name', 
    'type' => 'text', 
    'class' => 'input' 
); 

そして

$data = array(
    'name' => 'username' 
    'id' => 'username', 
    'type' => 'text', 
    'class' => 'input' 
); 
登録フォームは

so on...です。

次に、あなたは

+0

$this->input->post('name');はあなたに@Hekマットをありがとうござい使用してnameに基づいてフィールドを取得することができます。 idとnameの違いは何ですか? 私の参考のためだけです。 –

+1

フォームは常に 'names'フィールドに基づいてポストされます。あなたは' javascript'の検証や 'css'の定義にidを使うことができます。 –

関連する問題