CodeIgniter Forums
POST Question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: POST Question (/showthread.php?tid=29771)



POST Question - El Forum - 04-20-2010

[eluser]mrwilson1[/eluser]
I have two problems, the first is this:
I cannot make contact with any of my forms when hitting submit. Background on the forms is that they come from my first codeigniter site and work perfectly there. One is a login form and the other a blog entry form. The log in worked last week but I am afraid I must have changed a config item sometime. Where would one look to corral this type of problem. When I hit submit all that happens is the name and password or blog data disappears, but nothing else happens. Not even an error. In fact I have tried to echo out the form data upon submission but nothing shows up.

I know my routing setup is right.
Code:
$route['default_controller'] = "main";

Some of my config settings are

Code:
$config['base_url'] = "http://lemonrose.net/";

Code:
$system_folder = "ci/system";

$application_folder = "ci/application";

$autoload['libraries'] = array(
'input','database', 'session', 'form_validation', 'table', 'email', 'typography', 'pagination', 'trackback', 'user_agent');

$autoload['helper'] = array('url', 'html', 'date', 'form', 'array', 'email');

Please tell me what other info I can post.

The second problem is the dreaded index.php removal problem

I am using this to remove the index.php page. Again this is also from the first site and works perfectly. This works for my fist page refered to in the routing congfig but after that I have to use the index.php to connect links.

Code:
RewriteEngine on
# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

DirectoryIndex index.php
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]


I think I have tried to fix these simple problems enough that I am preventing them from working somehow.

Here is an example of one of the forms

Code:
echo validation_errors();
    
    echo form_open('log/login');//controller and function
    
    echo form_label('User', 'name');
    
    $data = array('name' => 'name', 'id' => 'name', 'maxlength' => '20', 'size' =>
        '10', 'placeholder' => 'UserName' );
        
    echo form_input($data);
    
    echo nbs(5);
    
    echo form_label('Password', 'pass');
    
    $data = array('name' => 'pass', 'id' => 'pass', 'maxlength' => '30', 'size' =>
        '20', 'placeholder' => 'Password' );
    echo form_password($data);
    
    echo nbs(5);
    
    echo form_label('Whats 10 + 11?', 'human');
    
    $data = array(
    'name'=>'human',
    'id'=>'human',
    'placeholder'=>'Human?',
    'maz_length'=> '2',
    'min_length'=> '2',
    'size'=>'10'    
    );
    echo form_input($data);
    
    echo form_submit('submit', 'Send');
    echo form_close();

Both codeigniter sites are on the same host. The forms are simple and should easily work. The database system works fine as I can log visitors and sessions. The controllers and models are mirror images of the ones that work on site one, adjusted for db names only(form fields are the same)

Thanks in advance


POST Question - El Forum - 04-20-2010

[eluser]Federico Baña[/eluser]
Please post your controller code, there should be the problem.

Check that you actually have a controller called "log" with a method called "login", and that inside that function you are trying to get (for example) the "name" variable from POST.
Other thing you can try doing is, if you're using $this->input->post(), use $_POST["name"] instead, you never know maybe it's something with the input library.

Let me know what you find out.


POST Question - El Forum - 04-20-2010

[eluser]mrwilson1[/eluser]
this is the controller

Code:
class Log extends Controller {

    function Log()
    {
        parent::Controller();    
    }
function login() {
    $data = array(
    'name'=> $this->input->post('name'),
    'pass' => $this->input->post('pass'),
    'human' => $this->input->post('human')    
    );
        
    $this->load->model('signin');
    $query = $this->signin->validate();
    
    if ($query) {
    $data = array(
    'name' => $this->input->post('name'),
    'pass' => hash('sha512', $this->input->post('pass')),
    'is_logged_in' => TRUE
    );
     $this->session->set_userdata($data);
    
    redirect('home/logged');
    } else {
        echo "signin not correct";
        //redirect('main'); //if the form doesnt validate reload the index function
    }
    }

And the model

Code:
function validate()
    {
        $this->db->where('name', $this->input->post('name'));
        $this->db->where('pass', hash('sha512', $this->input->post('pass')));
        $query = $this->db->get('users');

        if($query->num_rows == 1)
        {
            return true;
        }

    }

Using $_POST made no difference

The strange part in all this is that no forms work, its like a dead submit button on each


POST Question - El Forum - 04-20-2010

[eluser]Federico Baña[/eluser]
Your problem lies here:

Code:
if($query->num_rows == 1)
        {
            return true;
        }
The conditional always returns TRUE (if Im making the right math)

Should be this way:
Code:
if($query->num_rows() == 1)
        {
            return true;
        }

And I'd recommend you use strict comparatives when you know exactly which data type the function will be returning (like in this case)
Code:
if($query->num_rows() === 1)
        {
            return true;
        }

Try that and tell me the results


POST Question - El Forum - 04-20-2010

[eluser]mrwilson1[/eluser]
I note your changes and you are right about the strict comparison.

But nothing changes. I really feel the view/controller/model are right (given your changes). Are there any settings that can affect this in configuration? Its apparent that from the instant I hit submit that any action stops right there. I have checked the source on the pages with forms and they appear to be correct


POST Question - El Forum - 04-20-2010

[eluser]Federico Baña[/eluser]
the only thing i see could be happening to stop the script is that one where you missed the "()" after num_rows, i think that could be returning true then the controller makes the redirection, and when you get to the next page the scripts finds that you're not logged in so you fall back again in the first screen.

do you get my point?


POST Question - El Forum - 04-20-2010

[eluser]mrwilson1[/eluser]
Yes I understand what you are saying. Im going to update the form on the other site and see if that effects anything. I will keep plugging away at this, there has to be a truely strange reason why it doesn't work. I do check the sessions db to see if it logs in and it never does.

If it makes any difference, I am also having problems including files from other directorys within the views folder.

Thanks for your help and time Smile I appreciate it


POST Question - El Forum - 04-21-2010

[eluser]mrwilson1[/eluser]
@federico Bana,

Believe it or not, all my problems went away when I took a model out of auto load. Thanks again for your help