Welcome Guest, Not a member yet? Register   Sign In
CI Form Validation tutorial doesn't work
#1

[eluser]solkatten[/eluser]
I am following the tutorial:
http://ellislab.com/codeigniter/user-gui...ation.html
but I get the error 404 when clicking the Submit button. I can't figure out what's wrong.

My controller:
Code:
<?php
class Form extends Controller {
    
    function Form(){
    parent::Controller();
    $this->load->helper('url');
    $this->load->helper('form');
}

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

My view for the form:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Formulär&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

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

<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;!-- &lt;/form&gt; --&gt;
&lt;/body&gt;
&lt;/html&gt;

My view for the success message:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled&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;

When I change
Code:
if ($this->form_validation->run() == FALSE)
to
Code:
if ($this->form_validation->run() == TRUE)
the success page appears but when klicking on the link on the page it can't find the page (to the form).

My config:
Code:
$config['base_url']   = "http://webplace/susanne/codeigniter/";
$config['index_page'] = "form.php";
My routes:
Code:
$route['default_controller'] = "form";
#2

[eluser]LuckyFella73[/eluser]
I can't see errors that are defenitely responsible for you problem.
Just 2 questions:

1. Is there a specific reason why your form closing tag is commented out?

2. Why did you changed the config file from


Code:
$config['index_page'] = "index.php";

to
Code:
$config['index_page'] = "form.php";

Maybe that is why your anchor doesn't work after submitting the form.

$config['index_page'] is the index.php in your root path and not the first
page/ controller you want to be shown. That is defined by "default_controller"
in routes.php -> you allready edited that.
#3

[eluser]solkatten[/eluser]
[quote author="LuckyFella73" date="1267469175"]
1. Is there a specific reason why your form closing tag is commented out?
[/quote]

There is no start tag and the form_open() contains closing tag according to http://ellislab.com/codeigniter/user-gui...elper.html.
The error existed before I commented the closing tag.

[quote author="LuckyFella73" date="1267469175"]
2. Why did you changed the config file from

Code:
$config['index_page'] = "index.php";

to
Code:
$config['index_page'] = "form.php";

Maybe that is why your anchor doesn't work after submitting the form.

$config['index_page'] is the index.php in your root path and not the first
page/ controller you want to be shown. That is defined by "default_controller"
in routes.php -> you allready edited that.
[/quote]
When I did the blog tutorial I changed it and it worked so I just figured it was one of those places wich need changeing. But your explanation makes sence.

Right now I have:
Parse error: syntax error, unexpected ';' in /var/www/susanne/codeigniter/system/application/controllers/form.php on line 14
A file I haven't changed... :-S
#4

[eluser]LuckyFella73[/eluser]
In that file (your form controller):
Quote:codeigniter/system/application/controllers/form.php

you have a "(" (first character) which makes no sense:
Code:
($this->load->view('myform');

Try to remove and test again. And be sure that your
application/config/config.php file contains:

Code:
$config['index_page'] = "index.php";

in case you didn't rename "index.php" in your root folder
( .../www/susanne/codeigniter/index.php )

Hope that will solve your problem

hej hej
#5

[eluser]solkatten[/eluser]
[quote author="LuckyFella73" date="1267472990"]
you have a "(" (first character) which makes no sense:
Code:
($this->load->view('myform');
[/quote]

I think it is called temporary programming blindness :lol:

I have changed the config file AND NOW IT IS WORKING!

THANK YOU!
#6

[eluser]LuckyFella73[/eluser]
We all are not save of typos and will never be ...

Nice to hear that your form is working now Smile




Theme © iAndrew 2016 - Forum software by © MyBB