Welcome Guest, Not a member yet? Register   Sign In
CI 2.1.0 form $this->form_validation->run() always returns FALSE
#1

[eluser]Unknown[/eluser]
Hi all,

I'm using the form validation tutorial to get my forms working. I don't get errors back if I enter wrong data, and I don't get success if I enter right data.

This is what I did (exactly what the tutorial described).

Controller form.php:
Code:
<?php

class Form extends CI_Controller {

function index()
{
  $this->load->helper(array('form','url'));

  $this->load->library('form_validation');

  $this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');
  $this->form_validation->set_rules('password', 'Password', 'required');
  $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
  $this->form_validation->set_rules('email', 'Email', 'required|valid_email');

  if ($this->form_validation->run() == FALSE)
  {
     $this->load->view('myform');
  }
  else
  {
     $this->load->view('formsuccess');
  }
}
}

?>
View myform.php:
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<?php echo validation_errors(); ?>

<?php echo form_open('form'); ?>

<h5>Username</h5>
&lt;input type="text" name="username" value="" size="50" /&gt;

<h5>Password</h5>
&lt;input type="text" name="password" value="" size="50" /&gt;

<h5>Password Confirm</h5>
&lt;input type="text" name="passconf" value="" size="50" /&gt;

<h5>Email Address</h5>
&lt;input type="text" name="email" value="" size="50" /&gt;

<div>&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
View formsuccess.php:
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

<h3>Your form was successfully submitted!</h3>

<p>&lt;?php echo anchor('form', 'Try it again!'); ?&gt;</p>

&lt;/body&gt;
&lt;/html&gt;

I searched everywhere for solutions, and found issue #177, but the solution from github didn't help.

In a debugging session I found in library Form_validation.php in "function set_rules" and in "function run" the following statement:
Code:
....
  if (count($_POST) == 0)
  {
   return FALSE;
  }
....
This statement always returns FALSE, even if I enter correct data in the form fields.

Can anyone help me please?

Regards,

Carmen
#2

[eluser]Unknown[/eluser]
This error occur if we don't define, form Method parameter, e.g. method="get" or method = "post"
&lt;form name="myfrm" method="post"&gt;
&lt;/form&gt;


Hope this help someone.




Theme © iAndrew 2016 - Forum software by © MyBB