Welcome Guest, Not a member yet? Register   Sign In
Cannot get form_validation working, looks like $_POST datas aren't sent
#1

[eluser]blavaciko[/eluser]
I'm trying to get my forms working.
But i cannot run the validation on them.
I was using the user guide step by step, but it's not working, returning me empty form again.
I tried to echo username field value, but nothing happend
can anybody help me?
Controller
Code:
<?php

class Form extends Controller {
    
    function index()
    {
        $this->load->helper(array('form', 'url'));
            $this->load->view('myform');
        
    }
    
    function send()
    {
        $username = $this->input->post('username');
        echo $username;
        
        $this->load->helper(array('form', 'url'));
        
        $this->form_validation->set_rules('username', 'Username', 'required');
    
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
}
?>
View
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<?php echo validation_errors(); ?>

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

<h5>Username</h5>
&lt;input type="text" name="username" value="" id="username" 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;
#2

[eluser]nuwanda[/eluser]
You haven't loaded the validation library:

Code:
$this->load->library('form_validation');
#3

[eluser]blavaciko[/eluser]
I've got this in config/autoload.php
Code:
$autoload['libraries'] = array('database', 'form_validation');
anyway, it's not workin even loading is right in the controller
#4

[eluser]nuwanda[/eluser]
Seems no data is being posted back to your send function.

Put this before anything in your send function, input some data into the form, and see what gets output.

Code:
print_r($_POST);
exit;
#5

[eluser]blavaciko[/eluser]
only this appeared

Array ( )
#6

[eluser]johnpeace[/eluser]
Did you validate your HTML? I know the submit input needs a name...what does the &lt;form&gt; tag look like?
#7

[eluser]blavaciko[/eluser]
The source is like this
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action="http://skautskyples.sk/index.php/form/send" method="post"&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;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
#8

[eluser]blavaciko[/eluser]
I've sold it!

I'm using redirection for this site from domain example.com to something.com/example so i had to set the base_url to something.com/example and now everything's working.
thank's anyway




Theme © iAndrew 2016 - Forum software by © MyBB