Post variables are not recived at controller using code ignitor

205
February 07, 2017, at 11:36 PM

Post variable is received at controller.

View: 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');
?>

The Controller: 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;
   }
 }
}
?>

Even if you change Post to get then also there is no change in http request query.

The sign-in module is working fine but signup is not working.

I am new to code ignitor and php.

Answer 1

Change Method GET to POST

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

And

Foreach your field add name attribute like this..

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

And

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

And so on... for sign-up form.

Then you can get your fields based on name using $this->input->post('name');

READ ALSO
Find smallest thumbnail in WordPress mySQL database

Find smallest thumbnail in WordPress mySQL database

I have a PHP code that fetches a thumbnail from the WordPress mySQL database

349
Library or Utils own logs. Good or bad practice?

Library or Utils own logs. Good or bad practice?

I have a general question:

251
How rewrite url frindly for arabic website?

How rewrite url frindly for arabic website?

I need help or some resources to generate friendly url for arabic web site, with php orhtaccess, for latin caractere i can do that easy but for arabic i don't know how do that

337