Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Form validation always returning FALSE

Alright. I've been searching the forums and Google for a few days now, trying to figure out why the form validation is not working for my application, and I've come out empty handed. So I'm turning to you guys now for help. I'm on the verge of throwing my laptop out the window over this 8D So any help is appreciated.

I don't know why, but when I try to use the form_validation library on any form, it always returns FALSE and does not return any of the validation errors, regardless of the rules that I've placed for my fields. I've even tried this on the user_guide's form validation example code and received the same results.

I have the form_validation library auto-loaded, along with with the url and form helpers.

Here's my code, and a URL to the simple form based on the user_guide example:

URL: http://www.codeigniter.deadeyes-star.com/welcome/form


class Welcome extends Controller
    function __construct()

    function index()
        $this->template->build('welcome_message', $data);
    function form()
            $this->form_validation->set_rules('username', 'Username', 'required');
            $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');
            if ($this->form_validation->run() == FALSE)

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */

View - myform.php:
<title>My Form</title>

<h1>Form Validation Test</h1>

&lt;?php echo validation_errors(); ?&gt;

&lt;?php echo form_open('welcome/form'); ?&gt;

&lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?&gt;" size="50" /&gt;

&lt;input type="text" name="password" value="&lt;?php echo set_value('password'); ?&gt;" size="50" /&gt;

<h5>Password Confirm</h5>
&lt;input type="text" name="passconf" value="&lt;?php echo set_value('passconf'); ?&gt;" size="50" /&gt;

<h5>Email Address</h5>
&lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?&gt;" size="50" /&gt;

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



Again, any help is appreciated. Thanks in advance.


at the very end of your code the form close is missing.
&lt;?php echo form_close(); ?&gt;

Maybe that helps?


[quote author="mawi27" date="1282651001"]hi,

at the very end of your code the form close is missing.
&lt;?php echo form_close(); ?&gt;

Maybe that helps?


... forget it, i overlooked the &lt;/form&gt; tag.

Hur, yeah. I went ahead and changed it to codeigniter's form close function for consistency.

I'm still at a lost, wondering if my codeigniter install is corrupt? I'm thinking of starting from a clean install and slowly working my way up, re-adding my code and constantly checking the form validation to make sure it continues to work. But... I'd rather not, because that's a lot of work Smile

[eluser]Philipp GĂ©rard[/eluser]
Try a fresh install of CI on your server to check if the same form also does not work in the new "enviroment". If that happens, the error will be due to some server setting.


I tried your code and it's working. The only difference I see between yours
and the code I have in the welcome controller:
class Welcome extends Controller {

    function Welcome()

But maybe it's not causing the error .. don't know

Did you try some debugging like echo $this->input->post('username')
in your welcome/form method to check if the form posts the values?
Try to isolate the error step by step.

BTW: take "valid_email" as rule for your email field. This way the field
is requiered and checked for the right syntax

When I submit the form, then refresh, I don't get a notice that POST data will be resubmitted, which tells me that I'm being redirected (or for some other reason, $_POST is being lost)

Firebug is showing a 301 Moved permanently status. Is your .htaccess file doing something weird. If you dont mind can you post that?

I think this is the culprit

No, it's not that. I know codeigniter's user guide encourages us to use the PHP4 method to declare a class, but I use the PHP5 method. Seems cleaner to me. As such, I also use the MY_Controller method for my other pages, as described here.

But 8D I did go ahead and change the code to try it out, didn't change anything though.


@[email protected]
I used the same .htaccess that I used on my main (somewhat public) site, where the form validation works as it should. But, here it is:

RewriteEngine on
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]

I tried the.htaccess code from the page you provided, but... it still didn't change anything ):

Also, I do use Phil Sturgeon's template, module, and asset libraries. But disabled them from loading to see if they were the culprit somehow? But again, nothing.

Maybe I do need to just start with a clean install again and slowly work my way up. I'm out of idea's on what it could be.

Again, it looks like the page is being redirected. A GET request immediately following the POST from form submission.

Quote:16:01:59:942: Network: POST http://codeigniter.deadeyes-star.com/welcome/form
16:02:00:100: Network: GET http://www.codeigniter.deadeyes-star.com/welcome/form

Somewhere in your code you're redirecting from codeigniter.deadeyes-star.com to www.codeigniter.deadeyes-star.com, that's where your problem is.

Theme © iAndrew 2016 - Forum software by © MyBB