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

[eluser]kaisama[/eluser]
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

Controller:
Code:
<?php

class Welcome extends Controller
{
    function __construct()
    {
        parent::__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)
                {
                    $this->load->view('myform');
                }
            else
                {
                    $this->load->view('formsuccess');
                }
        }
}

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


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

<h1>Form Validation Test</h1>

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

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


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

<h5>Password</h5>
&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>

&lt;/form&gt;

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

Again, any help is appreciated. Thanks in advance.
#2

[eluser]kaejiavo[/eluser]
hi,

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

Maybe that helps?

Marco
#3

[eluser]kaejiavo[/eluser]
[quote author="mawi27" date="1282651001"]hi,

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

Maybe that helps?

Marco[/quote]


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

[eluser]kaisama[/eluser]
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
#5

[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.
#6

[eluser]LuckyFella73[/eluser]
Hi,

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

    function Welcome()
    {
        parent::Controller();    
    }

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
#7

[eluser]danmontgomery[/eluser]
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)
#8

[eluser]cideveloper[/eluser]
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
#9

[eluser]kaisama[/eluser]
@luckyfella73
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.

--

@progr@mmer
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:

Code:
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.
#10

[eluser]danmontgomery[/eluser]
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