• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Form Validation and Htaccess file

#21
[eluser]DavidHopkins[/eluser]
Cheers, I shall carryon having a dig about, its deffo something with the htaccess and how its dealing with my post,

i shall see !

Dave

#22
[eluser]InsiteFX[/eluser]
Dave, I will be on later.

But until then try setting a route to that controller/method in ./application/config/routes.php

Code:
$route['login/ProcessLogin'] = 'login/ProcessLogin';

#23
[eluser]InsiteFX[/eluser]
Dave, I set this up on my system and it runs fine coded like below with index.php removed.

./application/config/autoload.php
Add the url and form helpers.

./application/controllers/login.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* ------------------------------------------------------------------------
* Created by Php Designer 8.
* Date  : 5/28/2012
* Time  : 9:50:47 PM
* Author: Raymond L King Sr.
* The Learn CodeIgniter Development Team.
*
* Class Login Controller
*
* ------------------------------------------------------------------------
* To change this template use File | Settings | File Templates.
* ------------------------------------------------------------------------
*/

class Login extends CI_Controller {

/**
  * -----------------------------------------------------------------------
  * Class variables - public, private, protected and static.
  * -----------------------------------------------------------------------
  */


// ----------------------------------------------------------------------

/**
  *  __construct
  *
  * Class Constructor PHP 5+
  *
  * @access public
  * @return void
  */
public function __construct()
{
  parent::__construct();

}

// --------------------------------------------------------------------

/**
  * index()
  *
  * Default index method.
  *
  * @access public
  * @return void
  */
public function index()
{
  $data = array(
   '' => '',
  );

  $this->load->vars($data);
  $this->load->view('login');
}

public function process_login()
{
  $this->load->library('form_validation');

  $this->form_validation->set_rules('cid', 'a', 'trim|required|xss_clean');
  $this->form_validation->set_rules('email', 'b', 'trim|required|valid_email|xss_clean');
  $this->form_validation->set_rules('pass', 'c', 'trim|required|xss_clean');

  if ($this->form_validation->run() == FALSE)
  {
   echo "false<br />";
   $this->load->view('login', 'refresh');
  }
  else
  {
   echo "ok<br />";
   var_dump($this->input->post(NULL, TRUE));
   exit;
  }
}
}

/* ------------------------------------------------------------------------
* End of file login.php
* Location: ./application/controllers/login.php
* ------------------------------------------------------------------------
*/

./application/views/login.php
Code:
<div id="LoginContainer">
&lt;?php echo form_open('login/process_login');?&gt;

<h1>Login</h1>

<div id="LoginContainerRow">
  <div id="LoginContainerLabel">Account No:</div>
  <div id="LoginContainerInput">
   &lt;input type="text" name="cid" /&gt;
  </div>
    </div>

<div id="LoginContainerRow">
  <div id="LoginContainerLabel">Email Address:</div>
        <div id="LoginContainerInput">
   &lt;input type="text" name="email" /&gt;
  </div>
    </div>

<div id="LoginContainerRow">
  <div id="LoginContainerLabel">Password:</div>
        <div id="LoginContainerInput">
   &lt;input type="password" name="pass" /&gt;
  </div>
    </div>

    <div id="LoginContainerButton">
  &lt;input name="Submit" type="submit" value="Log In"/&gt;
    </div>

&lt;?php echo form_close(); ?&gt;
</div>

Code:
// link keyed into browser
http://localhost/apptesting/login

// and the var_dump
okarray(4) { ["cid"]=> string(3) "300" ["email"]=> string(13) "test@test.com" ["pass"]=> string(6) "202020" ["Submit"]=> string(6) "Log In" }


I think it was trying to use the url_helper before it was loaded...
Or because the input submit was missing the name=""

#24
[eluser]CroNiX[/eluser]
You might need to use a different method for $config['uri_protocol'] in /application/config/config.php

#25
[eluser]InsiteFX[/eluser]
Thanks CroNix, I forgot to mention what I was using.

I am using
Code:
$config['uri_protocol'] = 'REQUEST_URI';

#26
[eluser]DavidHopkins[/eluser]
Hey Guys,

Sorry to say none of the above has worked =[

I have however got a firefox addon, Live HTTP headers and discovered something intresting.

When i use no htaccess file and make use of index.php i get the following output

Quote:http://client.domain.co.uk/index.php/login/ProcessLogin

POST /index.php/login/ProcessLogin HTTP/1.1
Host: client.domain.co.uk
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://client.domain.co.uk/
Cookie: ci_session=a:5:{s:10:"session_id";s:32:"7c2c22c673b1cb07a5644be3974ef21b";s:10:"ip_address";s:11:"2.24.115.72";s:10:"user_agent";s:65:"Mozilla/5.0+(Windows+NT+6.1;+rv:12.0)+Gecko/20100101+Firefox/12.0";s:13:"last_activity";i:1338322877;s:9:"user_data";s:0:"";}74b2f94a9d13cece028d47f7a066b3c6
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
cid=g&email=gg&pass;=&checkSubmit=Log+In
HTTP/1.1 200 OK
Date: Tue, 29 May 2012 20:23:39 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.7
Vary: Accept-Encoding
Content-Type: text/html
Transfer-Encoding: chunked
X-OSSProxy: OSSProxy 1.3.333.307 (Build 333.307 Win32 en-us)(Feb 22 2012 18:20:37)
Connection: keep-alive

However when i use the htaccess and remove index.php i get this output

Quote:http://client.domain.co.uk/login/ProcessLogin

POST /login/ProcessLogin HTTP/1.1
Host: client.domain.co.uk
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://client.domain.co.uk/
Cookie: ci_session=a:5:{s:10:"session_id";s:32:"7c2c22c673b1cb07a5644be3974ef21b";s:10:"ip_address";s:11:"2.24.115.72";s:10:"user_agent";s:65:"Mozilla/5.0+(Windows+NT+6.1;+rv:12.0)+Gecko/20100101+Firefox/12.0";s:13:"last_activity";i:1338322877;s:9:"user_data";s:0:"";}74b2f94a9d13cece028d47f7a066b3c6
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
cid=g&email=gg&pass;=&checkSubmit=Log+In
HTTP/1.1 404 Not Found
Date: Tue, 29 May 2012 20:24:53 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.7
Vary: Accept-Encoding
Content-Type: text/html
Transfer-Encoding: chunked
X-OSSProxy: OSSProxy 1.3.333.307 (Build 333.307 Win32 en-us)(Feb 22 2012 18:20:37)
Connection: keep-alive
----------------------------------------------------------

I seem to get a HTTP/1.1 404 Not Found, im not sure why this is occurring. It is probably a server issue maybe ? Or is it something htaccess can resolve?

Mnay Thanks

David

#27
[eluser]gazza7364[/eluser]
This is just a thought, have you enabled rewrite in your web server, if you are using Apache 2 you need to enable this in mods_enabled, this can be done from the cli with sudo a2enmod rewrite. Also you need to set-up your default web directory with something like the following:-

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>


Any just a thought, you may have done this already.
I use ubuntu and this is what I forgot to do, thinking it was set by default.

#28
[eluser]InsiteFX[/eluser]
He already stated that hes running wordpress and that .htaccess file is working.

#29
[eluser]InsiteFX[/eluser]
Dave this is the FireBug info I am getting

Code:
localhost/apptesting/index.php/login/process_login

POST /apptesting/index.php/login/process_login HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://localhost/apptesting/index.php
Cookie: __utma=111872281.1781361048.1314086981.1314765697.1326477073.4; __utmz=111872281.1314086981.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); cisession=Xel8+uf4E2forMITBdh+frUvUjNqKm1maBvYFOlBhVQK/1hhLn6p54FKAmoQ7Y93OknjqV2veO3Y9U+EuXXeLd4gPNc32NhzbDKj7BXHA2Aw/8vPlN+7eevfXp0UaiRL+Qd72YCnmmeJaw2oqLZWtZ/nIOL99bDn81AfiFp5O/Ogz35E21TE/cmZYb1xlpwZIbcUANSz29FW9GqmBCiGw08gE/xYh7VuAEhs6T/BMduL2qRmq203zGMuLdBpORjg5txxqag7N0FDdZZrWm32s0irHaiDtysbBjb7mxW4QQQ0bqS/PsKvQVOGwxo1jl5zzk1+Pr/zHAYuOGgsyOfR50p4V0tb+WUo8NryBwkv3coqnK6p6g9pZKj5aj4COuu9

Code:
localhost/apptesting/login/process_login

POST /apptesting/login/process_login HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://localhost/apptesting/index.php
Cookie: __utma=111872281.1781361048.1314086981.1314765697.1326477073.4; __utmz=111872281.1314086981.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); cisession=uXupAT4rK7+YYiOfcPCJGjmJaMNopuvGQJohJvuh+PjVKSDrk63XKo7rbYx4s5aN+OY1NBW1Vk3ygSkL3zvxj0PRfaUtg0+lSO+Hxiz05+g786EV0Tns7zMOz867IoTGRdOTdvT6/lJvdkJKVHgf5OQPpqibJdk7BITPjqAH+x1hNSbaRWia2J5EHCSBMI96lIPSLAEB17pQ6cmdCkEf/EnzbR762zGde51KFVNlbtNQBMnmwQ2sfizh5m03hEEG3EJZMcVpLSR0q2lGOMjs50mDRAEjmCZtBk4jF+b1Bipnb6SsEDRL8GIOssSuyFQx6QCCDiBcefOhsvYNN9p+2V74EO78eoDHM+RyTCzyqYSCdN0JOhZr+D2CVZXNvgPy

Can you please show us your ./application/config/routes.php file

#30
[eluser]DavidHopkins[/eluser]
Hello,

My routes file is just the default that gets shipped, on all projects i have never had to make changes to this.

Edit
It does however have the additional route that you suggested a few posts back

Here is is thou

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| http://ellislab.com/codeigniter/user-guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There area two reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router what URI segments to use if those provided
| in the URL cannot be matched to a valid route.
|
*/

$route['default_controller'] = "home";
$route['404_override'] = '';
$route['login/ProcessLogin'] = 'login/ProcessLogin';

/* End of file routes.php */
/* Location: ./application/config/routes.php */


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.